Generalization

Generalization is the relationship between a more general classifier (class, use case, component, etc.) and a more specific one:

We refer to the destination of a generalization arrow the generalization or superclass, and the source as a specialization or subclass:

Generalization implies that the specific classifier inherits all of the features of the general classifier. This implies that instances of the specific classifier can be substituted for instances of the general classifier. For example:

Employee e = new SalariedEmployee();
e.pay(); // SalariedEmployee.pay() called
e = new PartTimeEmployee();
e.pay(); // PartTimeEmployee.pay() called

Notes

1. In Java generalization translates into the "extends" relationship:

class Airplane extends Vehicle { ... }

2. Sometimes I refer to the generalization arrow as the specialization or extends arrow.

3. Generalization is a transitive relationship. If A is a subclass of B and B is a subclass of C, then A is indirectly a subclass of C:

Subclasses versus Subsets

In a domain model generalization is often used to model the relationship between a set and its subsets. This kind of thing shows up in taxonomic hierarchies or when domain experts use phrases like "Every X is a Y".

This can be confusing. In the solution domain the features of a superclass are a subset of the features of a subclass. In other words, a subclass inherits all of the attributes and operations of a superclass, but may add more. Philosophers sometimes use the idea of intensional subset versus extensional subset to sort this out. A is an extensional subset of B if every member of A is literally a member of B. A is an intensional subset of B if every member of A can substitute for any member of B in all important contexts. A is a subclass of B means that A is an intensional subset of B but not necessarily an extensional subset.

More confusion: Members of a subclass may logically be members of a superclass in terms of properties, but not necessarily in terms of behaviors. This can happen when members of a class are mutable (i.e., can change their properties without changing their identity).

In the following example we attempt to model the true statement "every square is a rectangle" using generalization. Note that we add a constraint to the Square class that the inherited length and width attributes should be equal:

However, this constraint may be awkward to enforce if Rectangle is a mutable class. In other words, if Rectangle provides setWidth and setLength methods.