Logical View  «Prev  Next»
 Lesson 10 Generalization Objective Define the notation for specifying inheritance.

### Generalization

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.

### Generalization hierarchy

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.

1. To start the model begin with the dog class.
2. Identify the discriminator for the next level of differentiation or specialization, for example, Breed.
3. Connect all of the Breed level classes to the Dog class using the generalization type of association, the triangle at the superclass end of the association.
4. Place the discriminator on the generalization line.
5. To further specialize the hierarchy, select the discriminator for the next level. For example, break down Breed into sub-breeds, or sub-classes of the Spaniel class.
6. Connect the new sub-classes to the Spaniel class, again using the generalization symbol. Place the discriminator on the generalization line.

Generalization visibility
In the next lesson, you will learn a valuable alternative to inheritance called delegation.

### Composition Context Generalization- Quiz

Click the Quiz link below to take a short multiple-choice quiz on composition context and generalization.
Composition Context Generalization- Quiz