06 - Abstract (Compatibility Mode)
06 - Abstract (Compatibility Mode)
Object-Oriented Programming
Outline
Abstract classes
Abstract methods
Design pattern: Template method
Dynamic & static binding
Upcasting & Downcasting
Readings:
HFJ: Ch. 8.
GT: Ch. 8.
Fine. But…
How do we know
when a class should
be abstract?
mobile phone
smart phone
iPhone
iPhone 4
iPhone 4S
Upcasting: Downcasting:
casting up the diagram. casting down the diagram.
Object
Object o = new Cow(); Object o;
...
Cow c = (Cow) o;
implicit casting
from Cow to Object Cow
explicit casting
from Object to Cow
+ moo()
As a super class
A common superclass for several subclasses
Factor up common behavior
Define the methods all the subclasses respond to
As an abstract class
Force concrete subclasses to override methods that are
declared as abstract in the super class
Circle, Triangle must implement their own draw() and erase()
Forbid creation of instants of the abstract superclass
Shape objects are not allowed