2.5. Abstract ClassesAn abstract class is typically a class that provides an operation signature, but no implementation; however, you can have an abstract class that has no operations at all. An abstract class is useful for identifying common functionality across several types of objects. For example, you can have an abstract class named Movable. A Movable object has a current position and the ability to move somewhere else using an operation named move( ). There can be several specializations of this abstract classa Car, a Grasshopper, and a Person, each of which provides a different implementation of move( ). Because the base class Movable doesn't have an implementation for move( ), the class is said to be abstract. You show a class is abstract by writing its name in italics. Show each abstract operation in italics as well. Figure 2-20 is an example of the abstract class Movable. Figure 2-20. Abstract classAn abstract class can't be instantiated; it must be subclassed and then a subclass which does provide the operation implementation can be instantiated. See "Relationships" for more information on subclasses. |