Generalization Relationships
A generalization relationship (sometimes called an is-a relationship) indicates that a specialized (child) model element is based on a general (parent) model element. The parent model element can have one or more children, and any child model element can have one or more parents. It is more common to have a single parent and multiple children. To comply with UML semantics, the related model elements must be the same type; a generalization relationship can be created from actor to actor or from use case to use case; however, it cannot be created from actor to use case.
For example, in an e-commerce application for a site that sells a variety of merchandise, an "inventory" class may be a parent class (also called a superclass). This class contains the attributes, such as "price," and operations, such as "setPrice," that all pieces of merchandise use. After defining this parent class, a child class (also called a subclass) is created for each type of merchandise, such as books and VCRs. The "book" class uses the attributes and operations in the "inventory" class and then adds attributes such as "author" and operations such as "setAuthor." A VCR class also uses the attributes and operations in the "inventory" class, but it adds attributes such as "manufacturer" and operations such as "setManufacturer," which are different from those in the book class.
Connector
A generalization appears as a solid line with an unfilled arrowhead pointing from the specialized (child) model element to the general (parent) model element.
Single Parent and Single Child |
Single Parent with Multiple Children (Inheritance Tree) | |
Using Generalization Relationships
You can add generalization relationships to your model to capture attributes, operations, and relationships in a parent model element and then reuse them in one or more child model elements. Because the child model elements in generalizations inherit the attributes, operations, and relationships of the parent, you need to define for the child only those attributes, operations, or relationships that are distinct from its parent.
The generalization relationships in a model appear in a variety of diagrams, including class, component, and use-case diagrams.
Naming Conventions
Generalization relationships usually do not have names. If you name a generalization relationship, the name appears next to the generalization connector on the diagram.
Related Topics
- Adding and Modifying Relationships
- Working with Class Diagrams
- Working with Component Diagrams
- Working with Use-Case Diagrams
|