Ch 8 Flashcards
Inheritance
The property that instances of a child class (or subclass) can access both data and behavior (methods) associated with a parent class (or superclass).
Extension
Inheritance means that the behavior and data associated with child classes are always an extension (i.e. a larger set) of the properties associated with the parent classes. A subclass will have all the properties of the parent class and other properties as well.
Contraction
Since a child class is a more specialized (or restricted) form of the parent class, it is also, in a certain sense, a contraction of the parent type.
Reasons to use inheritance
There are two main reasons to use inheritance:
1) . Inheritance as a means of code reuse. Because a child class can inherit behavior from a parent class, the code does not need to be rewritten for the child.
2) . Inheritance as a means of concept reuse. This occurs when a child class overrides behavior defined in the parent. Although no code is shared between the parent and child, the child and parent share the definition of the method.
Subclassing for specialization
The child class is a special case of the parent class; in other words, the child class is a subtype of the parent class.
Subclass for specification
The parent class defines behavior that is implemented in the child class but not in the parent class.
Subclass for construction
The child class makes use of the behavior provided by the parent class but is not a subtype of the parent class.
Subclass for generalization
The child class modifies or overrides some of the methods of the parent class.
Subclass for extension
The child class adds new functionality to the parent class but does not change any inherited behavior.
Subclass for limitation
The child class restricts the use of some of the behavior inherited from the parent class.
Subclass for variance
The child class and parent class are variants of each other, and the class-subclass relationship is arbitrary.
Subclass for combination
The child class inherits features from more than one parent class. This is multiple inheritance.
Singleton
An object that there only ever will be one instance of within a program.
Benefits of inheritance
Software reusability, code sharing, consistency of interface, software components, rapid prototyping, polymorphism & frameworks, information hiding.
Costs of inheritance
Execution speed, program size, message-passing overhead, program complexity.