-
Notifications
You must be signed in to change notification settings - Fork 17
Generalization
Generalizing into superclasses and splitting into subclasses is an important and valuable part of domain modelling. Inheritance from superclasses to subclasses reduces duplication in the model and makes sure common concepts are treated in the same manner.
An example of subclasses and superclasses is shown in the figure. Vehicle is a superclass for the subclasses Car and Train.
An other example, from ISO19157 - Data quality shows the abstract superclass DQ_Result with subclasses for different result types:
The main motivation for splitting a class into subclasses is if there are attributes, associations and/or operations that apply only to a minor selection of the class.
For example, the attributes on each subclass under DQ_Result apply only to a spesific kind for result. But there may also be situations where the motivation is only that the subclass is conceptual different from other subclasses, even without special attributes, associations and operations. The train subclass is an example here. It has no special attributes or associations in the model, but it is something conceptual different from a car. Subclasses are valuable for reducing duplication of attibutes, associations and operations, but must be used with care. Unnecessary subclasses makes the model more complex. Do not create subclasses without the motivations above.
There may also be situations where the question if whether or not an existing class can be added as a subclass of another class. In such, cases, two simple rules shall be concerned:
- 100% rule: All of the superclass's required attributes and associations must be applicable also for the subclass
- Is a-rule: In a natural language - test the sentence subclass is a superclass (train is a vehicle)
.... often, a superclass will be abstract, while the subclasses are the ones that are implemented.