Download presentation
Presentation is loading. Please wait.
Published byNaomi Marcia Gibbs Modified over 8 years ago
1
CS 210 Introduction to OO Design August 24, 2006 http://breeze.lcsee.wvu.edu/cs210
2
Polymorphism Many faces of an Object
3
Polymorphism Ability to communicate to objects that don’t even exist when initial design was created! Use methods defined in parent class on child class Object 1 print object display object pdf object print object display object Word object print object display object new object print object display object
4
A simple example* animal type eats sound herbivore type eats sound carnivore type eats sound omnivore type eats sound elephant type eats sound lion type eats sound bear type eats sound Does it make sense to instantiate these classes? *Adapted from Head First Java, O’Reilly Press
5
Abstract Classes When it does not make sense to instantiate a particular class, but it makes sense to define them for the purpose of organization, use an “Abstract” class. Abstract class cannot be instantiated – they can only be “extended” Abstract classes can have abstract methods as well.. These methods have to be implemented in the concrete classes.
6
Role of Interfaces How does one deal with multiple inheritance?
7
Multiple Inheritance animal eats sound cat eats sound dog eats sound hippo eats sound pet Rollover?
8
Problem with multiple inheritance* Digirecord burn() DVDBurner burn() CDBurner burn() ComboBurner burn() *Adapted from Head First Java, O’Reilly Press
9
Java approach Use Interfaces Classes can “extend” classes and they can “implement” interfaces.
10
Multiple Inheritance – make Pet class an interface animal eats sound cat eats sound dog eats sound hippo eats sound pet Rollover?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.