CS425 Lecture 8 Jan M. Allbeck. Announcements  Next few classes in Robinson 203B  No == (floating point comparison)  EA Information session, tomorrow.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Basic Object-Oriented concepts. Concept: An object has behaviors In old style programming, you had: –data, which was completely passive –functions, which.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Chapter 1 OO using C++. Abstract Data Types Before we begin we should know how to accomplish the goal of the program We should know all the input and.
CS 211 Inheritance AAA.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Inheritance Reserved word protected Reserved word super
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
Tips for Working Successfully in a Group Disclaimer: This is not a “good” format for a presentation. There is too much text on the pages.
Static and Dynamic Behavior Fall 2005 OOPD John Anthony.
Inheritance, Polymorphism, and Virtual Functions
Chapter 10 Classes Continued
Interactive Media and Game Development Project. Introduction ARG story: –monolithic game corporation (like EA) is trying to take over the world –using.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
Inheritance in C++ CS-1030 Dr. Mark L. Hornick.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
1 Time Management. 2 Remember that time is money Ben Franklin, 1748 Advice to a young tradesman.
Basic Object- Oriented Concepts Presented By: George Pefanis 21-Sep-15.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
CSSE501 Object-Oriented Development. Chapter 11: Static and Dynamic Behavior  In this chapter we will examine the differences between static and dynamic.
BIT 115: Introduction To Programming LECTURE 3 Instructor: Craig Duckett
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
Copyright 2006 Oxford Consulting, Ltd1 February Polymorphism Polymorphism Polymorphism is a major strength of an object centered paradigm Same.
CSCI-383 Object-Oriented Programming & Design Lecture 18.
Copyright © 2012 Pearson Education, Inc. Chapter 15: Inheritance, Polymorphism, and Virtual Functions.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Strengthening Your Interpersonal Relationships. 1. Don’t criticize, condemn, or complain about people.  There’s no faster way create resentment toward.
CPS Inheritance and the Yahtzee program l In version of Yahtzee given previously, scorecard.h held information about every score-card entry, e.g.,
Copyright © 2005 Elsevier Object-Oriented Programming Control or PROCESS abstraction is a very old idea (subroutines!), though few languages provide it.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CS212: Object Oriented Analysis and Design Lecture 16: Runtime Polymorphism.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Overview of C++ Polymorphism
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Basic Object-Oriented concepts. Concept: Classes describe objects Every object belongs to (is an instance of) a class An object may have fields –The class.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
OOP Basics Classes & Methods (c) IDMS/SQL News
1. Don’t criticize, condemn, or complain about people. There’s no faster way create resentment toward you than to criticize or complain about a person.
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
Starting Out with C++, 3 rd Edition 1 Chapter 13 – Introduction to Classes Procedural and Object-Oriented Programming Procedural programming is a method.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
CSCE 240 – Intro to Software Engineering Lecture 3.
Lecture 10 – Polymorphism Nancy Harris with additional slides Professor Adams from Lewis & Bernstein.
CS 3370 – C++ Object-oriented Programming
Object Oriented Programming
Java Programming Language
Virtual Functions Department of CSE, BUET Chapter 10.
Inheritance, Polymorphism, and Virtual Functions
CISC/CMPE320 - Prof. McLeod
Java Inheritance.
CISC/CMPE320 - Prof. McLeod
Overview of C++ Polymorphism
Lecture 10 Concepts of Programming Languages
Presentation transcript:

CS425 Lecture 8 Jan M. Allbeck

Announcements  Next few classes in Robinson 203B  No == (floating point comparison)  EA Information session, tomorrow at 1:30, Center for Arts, Grand Tier III  Got Game?  Game design competition  Mason athletics  Flash  More to come  Game Design?

Polymorphism  Extend a superclass to modify or extend behavior  Write an algorithm for a generic class and have it apply to all subclasses  Make a data structure for a generic class

Inheritance  In Java  Every class had exactly one superclass  Abstract classes and abstract methods  Implementing multiple interfaces  In C++  No interfaces  Multiple inheritance of classes

Inheritance  Java:  public class A extends B {…}  public class A implements C, D {…}  C++:  class A : public B {…};  class A : public C, public D {…};

Overriding Methods class A{ public: void bla() {std::cout << “bla” << std::endl;} }; class B : public A{ public: void bla(){std::cout << “quack” << std::endl;} }; int main(int argc, char** argv){ A* a = new B; a->bla(); } We might expect it to output “quack” but …

Dynamic vs. Static Binding  Methods are not inherently dynamically bound in C++  What method to run is based on the static/compile time type (A)  We might want it to deal with the runtime/dynamic type (B)

Virtual methods class A{ public: virtual void bla() {std::cout << “bla” << std::endl;} };  Make a method virtual and C++ knows to determine what method to execute based on the dynamic type.

How? The vtable  The vtable stores pointers to a class’s virtual methods, resolved at runtime  So why is this not the default?  Drawback: requires an extra dereference and some overhead  Flexibility is worth it

Pure Virtual Methods  No formal abstract class in C++  Implicitly created when you have a pure virtual method  Declare an “abstract” method:  virtual void bla = 0;  Implementation is required in subclasses that you want to instantiate.

Pure virtual methods class A{ public: virtual void bla() = 0; }; class B : public A{ public: void bla(){std::cout<<"quack"<<std::endl;} }; A is abstract and cannot be instantiated, but B can be.

Virtual Destructors A* a = new B(); delete a;  It’s generally a good idea to have a virtual destructor; even if it does nothing. ~A()What happens noneno destructor is called (even if B has one) non-virtualonly A’s destructor will be called virtualboth destructors get called

A Common Supertype  In Java, everything was an Object  You could always say…  Object o = new Anything();  In C++, there’s no equivalent hierarchy  void * can point to anything however

Why public A?  By sub-classing A via “class B: public A{…}”, we allow all of A’s public members to be public in B.  We can restrict this via private and protected to prevent public members from being called.

Parent’s Constructor  In Java  super();  super(parameters);  In C++  A::A():parent(){…}  A::A(int i):parent(i){…}  We can also initialize instance variables using this syntax in C++.

Multiple Inheritance  No interfaces because C++ supports multiple inheritance  class A: public B, public C {…};  Useful, but potentially problematic

Diamond Problem class Person{…}; class Terminator: public Person{…}; class Governor: public Person{…}; class Governator: public Terminator, public Governor {…};

Which Method?  In a situation like this, if both Terminator and Governor have overridden a method in Person, there will be some ambiguity in a Governator’s behavior.

Slicing Problem A a= B() Space for ASpace for inherited A members Extra B members

Teams of 3  me by Friday, Nov. 6 th or I’ll assign the groups.  Break up tasks  Document who is responsible for each task  Make an integration plan  Subversion  Plan to demo your individual components  Document choices  If there are problems, try to work them out, but also let me know.

Randy Pausch’s Tips for Working Successfully in a Group  Meet people properly.  It all starts with the introduction. Then, exchange contact information, and make sure you know how to pronounce everyone’s names. Exchange phone #s, [ addresses] and find out what hours are acceptable to call during.  Find things you have in common.  You can almost always find something in common with another person, and starting from that baseline, it’s much easier to then address issues where you have differences. This is why cities like professional sports teams, which are socially galvanizing forces that cut across boundaries of race and wealth. If nothing else, you probably have in common things like the weather.

 Make meeting conditions good.  Have a large surface to write on, make sure the room is quiet and warm enough, and that there aren’t lots of distractions. Make sure no one is hungry, cold, or tired. Meet over a meal if you can; food softens a meeting. That’s why they "do lunch" in Hollywood.  Let everyone talk.  Even if you think what they’re saying is stupid. Cutting someone off is rude, and not worth whatever small time gain you might make. Don’t finish someone’s sentences for him or her; they can do it for themselves. And remember: talking louder or faster doesn’t make your idea any better.  Check your egos at the door.  When you discuss ideas, immediately label them and write them down. The labels should be descriptive of the idea, not the originator: "the troll bridge story," not "Jane’s story."

 Praise each other.  Find something nice to say, even if it’s a stretch. Even the worst of ideas has a silver lining inside it, if you just look hard enough. Focus on the good, praise it, and then raise any objections or concerns you have about the rest of it.  Put it in writing.  Always write down who is responsible for what, by when. Be concrete. Arrange meetings by , and establish accountability. Never assume that someone’s roommate will deliver a phone message. Also, remember that "politics is when you have more than 2 people" – with that in mind, always CC (carbon copy) any piece of within the group, or to me, to all members of the group. This rule should never be violated; don’t try to guess what your group mates might or might not want to hear about.

 Be open and honest.  Talk with your group members if there’s a problem, and talk with me if you think you need help. The whole point of this course is that it’s tough to work across cultures. If we all go into it knowing that’s an issue, we should be comfortable discussing problems when they arise -- after all, that’s what this course is really about. Be forgiving when people make mistakes, but don’t be afraid to raise the issues when they come up,  Avoid conflict at all costs.  When stress occurs and tempers flare, take a short break. Clear your heads, apologize, and take another stab at it. Apologize for upsetting your peers, even if you think someone else was primarily at fault; the goal is to work together, not start a legal battle over whose transgressions were worse. It takes two to have an argument, so be the peacemaker.  Phrase alternatives as questions.  Instead of "I think we should do A, not B," try "What if we did A, instead of B?" That allows people to offer comments, rather than defend one choice.

Some of what I’ll be looking for…  DOCUMENTATION  Navigation  Different NPCs  Robots  Hostages  Hostiles  Different actions  Walk, pick up, detonate, freeze, etc  Different AIs  Player interface  Object oriented design  Interesting environment: layout and objects  Integration/group work  Impression of work put in (ask for help if you just stuck)  Playable, fun  Extras/polish

Calendar 11/10Player interfaces or Physics Group meeting 11/17Physics or something else Group meeting 11/24Class debugging Group meeting 12/1Demos I 12/8Demos II Review for final 12/15Final