UML uses the term generalization to specify the classification relationship between a general element and a more specific element. In fact, the term 'generalization' specifies a viewpoint focused on a classification hierarchy. For example, an animal is a more general concept than a cat, a dog, or a raccoon. Conversely, a cat is a more specialized concept than an animal.
The more specific element may contain information that is particular to it, as long as it remains completely consistent with the description of the more general element. Generalization applies mainly to classes, packages and use cases.
In the case of classes, the generalization relationship expresses the fact that the elements of one class are also described by another class (in fact, by the type of another class). The generalization relationship signifies 'is a' or 'is a kind of'. A cat is an animal; that has to do with generalization. A cat has two ears; that does not have to do with generalization, but rather with composition.
The generalization relationship is represented by an arrow that points from the more specialized class to the more general class. The tip of the arrow is an empty triangle, which allows it to be distinguished from the open arrow that symbolizes the navigation property of associations. In the following example, the
class is an abstraction of the classes Animal
, Cat
and Dog
.Raccoon
In the above example, the
class is called a superclass, and the classes Animal
, Cat
and Dog
are referred to as subclasses of the Raccoon
class.Animal
In the case of multiple subclasses, the arrows may be aggregated in a single arrow, as before, or represented independently as shown below. These two different ways of symbolizing generalization do not carry any particular meaning.
The attributes, operations, relationships and constraints defined in the superclasses are fully inherited in the subclasses. When programming, the generalization relationship is very often implemented using the inheritance relationship between classes, as supplied by object-oriented languages. Inheritance is one way to implement classification, but it is not the only one. The generalization relationship defined by UML is more abstract than the inheritance relationship as it exists in object-oriented programming languages like C++. Inheritance is a static relationship; it implies a very strong coupling between classes and is less well adapted to the concept of dynamic classificationm, or to the concept of metamorphosis. During analysis, it is better to talk about generalization or classification, and to worry about implementing generalization later, as part of the design stage.
Classes may have several superclasses. When this is the case, generalization is said to be 'multiple', and several arrows are drawn from the subclass to the various superclasses. Multiple generalization is the fusion of several classes into a single one. Superclasses do not necessarily have a common ancestor. In the example below, the Flying
class has two completely disjoint ancestors, the classes carpet
and Carpet
. The kind of generalization that groups the classes Vehicle
, Vehicle
Land
, vehicle
Air
and vehicle
Flying
is called diamond generalization.carpet
To convince yourself that carpets are indeed land vehicles, just look at my children...
A class may be specialized according to several simultaneous criteria. Each generalization criterion is indicated in the diagram by associating a discriminator with the generalization relationship. When arrows are aggregated, the discriminator only appears once. The absence of a discriminator is considered a particular case of generalization.
Example of generalization according to independent criteria.
Different constraints may be applied to generalization relationships in order, for example, to distinguish exclusive generalization variants from inclusive ones. Constraints on generalization relationships are represented using parenthesized expressions that are directly attached to the aggregated generalizations, or associated with a dotted line that links the generalization relationships concerned.
By default, generalization symbolizes an exclusive decomposition; that is, an object can only be an instance of one of the subclasses. The constraint
indicates that a class descended from class {disjoint}
may only be the descendant of one of the subclasses of A
.A
The constraint
indicates that a class which is a descendant of class {overlapping}
belongs to the Cartesian product of the subclasses of class A
. A concrete object is then built from a class obtained by mixing several superclasses.A
Example of inclusive classification
The constraint
indicates that the generalization is finished, and that it is no longer possible to add subclasses. Conversely, the constraint {complete}
specifies an extensible generalization.{incomplete}
The constraint
must not be confused with an incomplete view. A constraint carries semantic content that affects the model. An incomplete view does not mean that the model is incomplete. In general, a partial view is represented symbolically by an ellipsis that replaces model elements in various diagrams. The following example partially illustrates the generalization of the class {incomplete}
.Course
© 1997 Editions, Eyrolles, Paris, France . All rights reserved.