6.1 Abstract Class: Partial Blueprints
An Abstract Class is a restricted class declared with the abstract keyword that cannot be directly instantiated with new. It is engineered to serve as a foundational superclass for related derived classes.
An abstract class can contain both abstract methods (declared without body, forcing subclasses to implement them) and concrete methods (fully implemented, providing shared inherited functionality).
6.2 Interface: Pure Behavioral Contracts
An Interface is a formal contract specifying a collection of abstract method signatures that an implementing class must define. Interfaces contain zero instance state (all variables are implicitly public static final constants).
Figure 6.1: Abstract classes establish shared state and code reuse; Interfaces define contract capabilities across unrelated class hierarchies.
6.3 Object Relationships: Association, Aggregation & Composition
Beyond "IS-A" inheritance, OOP architectures model how independent objects connect and interact. These fall into three distinct relationships of increasing tightness:
- Association (Uses-A): A loose peer relationship between two autonomous objects where neither owns the other. Both can exist independently (e.g.
TeacherandStudent). - Aggregation (Has-A, Weak): A whole-part relationship where a container object contains references to parts, but the parts have an independent lifecycle. If the container is destroyed, the parts survive (e.g. A
DepartmenthasProfessors; if the department closes, professors still exist). Represented in UML by an empty diamond. - Composition (Has-A, Strong): A strict whole-part relationship with tightly bound lifecycles. The part cannot exist without the whole. Destroying the container immediately destroys all composite parts (e.g. A
HousehasRooms; if the house is destroyed, the rooms cease to exist). Represented in UML by a solid filled diamond.
Figure 6.2: Structural differentiation between loose Association, weak Aggregation (empty diamond), and life-bound Composition (filled diamond).