Generalization is the process of factoring classes to define a hierarchy of shared elements organized into classes. Words such as "kind of" or "type of" are often used to describe the generalization association. The generalization association is unlike any other association, in fact association and generalization are treated as separate model elements. Associations draw relationships between separate objects. Generalization links classes together where each class contains a subset of the elements needed to define a single object. Instantiating all the element subsets from each of the classes in a single vertical column of the generalization results in a single object. Consequently multiplicity, roles, and constraints are not used with
generalization.
To draw a generalization association, use a triangle at the
superclass end of the generalization line and connect the other end of the generalization to the
subclass. Add the discriminator on the generalization line in simple text.
The discriminator is a value or rule that distinguishes the subclasses from one another.Proper use of the discriminator facilitates the use of design patterns such as abstract factory.
Building a generalization hierarchy can work in two directions, from the most general class down to the most specialized classes (specialization), and from the most specialized classes to the most generalized class (generalization). Let us build from general down to specifics, using the class Dog. We need to keep track of various breeds in a dog school to understand and anticipate their unique training requirements.