- Inheritance
- Software reusability
- Create new class from existing class
- Absorb existing class's data and behaviors
- Enhance with new capabilities
- Derived class inherits from base class
- Derived class
- More specialized group of objects
- Behaviors inherited from base class; can customize
- Additional behaviors
- Class hierarchy
- Direct base class; inherited explicitly (one level up hierarchy)
- Indirect base class; inherited two or more levels up hierarchy
- Single inheritance; inherits from one base class
- Multiple inheritance; Inherits from multiple base classes (Base classes possibly unrelated ); Chapter 22
- Three types of inheritance
- public
- Every object of derived class also object of base class
- Base-class objects not objects of derived classes
- Example: All cars vehicles, but not all vehicles cars
- Can access non-private members of base class
- Derived class can effect change to private base-class members
- Through inherited non-private member functions
- private
- Alternative to composition
- Chapter 17
- protected
- Abstraction
- Focus on commonalities among objects in system; "is-a" vs. "has-a"
- "is-a"
- Inheritance
- Derived class object treated as base class object
- Example: Car is a vehicle; Vehicle properties/behaviors also car properties/behaviors
- "has-a"
- Composition
- Object contains one or more objects of other classes as members
- Example: Car has a steering wheel
2004-11-29