Download presentation
Presentation is loading. Please wait.
Published byArlene Wade Modified over 9 years ago
1
CS425 Lecture 8 Jan M. Allbeck
2
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?
3
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
4
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
5
Inheritance Java: public class A extends B {…} public class A implements C, D {…} C++: class A : public B {…}; class A : public C, public D {…};
6
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 …
7
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)
8
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.
9
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
10
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.
11
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.
12
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
13
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
14
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.
15
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++.
16
Multiple Inheritance No interfaces because C++ supports multiple inheritance class A: public B, public C {…}; Useful, but potentially problematic
17
Diamond Problem class Person{…}; class Terminator: public Person{…}; class Governor: public Person{…}; class Governator: public Terminator, public Governor {…};
18
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.
19
Slicing Problem A a= B() Space for ASpace for inherited A members Extra B members
20
Teams of 3 Email 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.
21
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, [email 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.
22
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."
23
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 email, 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 email 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.
24
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.
25
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
26
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.