Table of Contents
The concept of a subtype, or subclass, is a fundamental concept in natural language, mathematics, and informatics. For instance, in English, we say that a bird is an animal, or the class of all birds is a subclass of the class of all animals. In linguistics, the noun "bird" is a hyponym of the noun "animal".
An object type may be specialized by subtypes (for instance, Bird is specialized by Parrot) or generalized by supertypes (for instance, Bird and Mammal are generalized by Animal). Specialization and generalization are two sides of the same coin.
A subtype inherits all features from its supertypes. When a subtype inherits attributes, associations and constraints from a supertype, this means that these features need not be repeatedly rendered for the subtype in the class diagram, but the reader of the diagram has to understand that all features of a supertype also apply to its subtypes.
When an object type has more than one direct supertype, we have a case of multiple inheritance, which is common in conceptual modeling, but prohibited in many object-oriented programming languages, such as Java and C#, which only allow class hierarchies with a unique direct supertype for each object type.
A new object type may be introduced by specialization whenever it represents a special case of another object
type. We illustrate this for our example model where we want to capture
text books and biographies as special cases of books. This means that text
books and biographies also have an ISBN, a title and a publishing year,
but in addition they have further features such as the attribute
subjectArea
for text books and the attribute
about
for biographies. Consequently, in Figure 16.1, we introduce
the object types TextBook
and Biography
by
specializing the object type Book
, that is, as subtypes of
Book
.
When specializing an object type, we define additional features for
the newly added subtype. In many cases, these additional features are more
specific properties. For instance, in the case of TextBook
specializing Book
, we define the additional attribute
subjectArea
. In some programming languages, such as in Java,
it is therefore said that the subtype extends the supertype.
However, we can also specialize an object type without defining additional properties or operations/methods, but by defining additional constraints.