32.2. Generalization
The concepts CashPayment, CreditPayment, and CheckPayment are all very similar. In this situation, it is possible (and usefulclass hierarchy) in which the superclass Payment represents a more general concept, and the subclasses more specialized ones.
[1] Later in the chapter, we will investigate reasons to define class hierarchies.
Figure 32.1. Generalization-specialization hierarchy.
Generalization is the activity of identifying commonality among concepts and defining superclass (general concept) and subclass (specialized concept) relationships. It is a way to construct taxonomic classifications among concepts which are then illustrated in class hierarchies.Identifying a superclass and subclasses is of value in a domain model because their presence allows us to understand concepts in more general, refined and abstract terms. It leads to economy of expression, improved comprehension and a reduction in repeated information. And although we are focusing now on the UP Domain Model and not the software Design Model, the later design and implementation of super- and subclass as software classes that use inheritance yields better software.Thus:
Guideline Identify domain superclasses and subclasses relevant to the current iteration, and illustrate them in the Domain Model. |
To review the generalization notation introduced in a prior chapter, in the UML the generalization relationship between elements is indicated with a large hollow triangle pointing to the more general element from the more specialized one (see Figure 32.2). Either a separate target or shared target arrow style may be used.
Figure 32.2. Class hierarchy with separate and shared arrow notations.
[View full size image]