Subtypes

Let’s learn about subtypes.

The concept of a subtype, or a 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, such as bird and mammal can be generalized by animal. . Specialization and generalization are two ways of looking at this idea.

A subtype inherits all features from its supertypes. When a subtype inherits attributes, associations, and constraints from a supertype, this means that these features don’t need to be repeatedly rendered for the subtype in the class diagram. It’s important for the reader of the diagram 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. This is common in conceptual modeling, however, it’s prohibited in many object-oriented programming languages, such as Java and C#. These languages only allow class hierarchies with a unique direct supertype for each object type.

Introducing subtypes by specialization

A new object type can be introduced by specialization whenever it represents a special case of another object type. A good example of this is when we categorize textbooks and biographies as different genres of books. Textbooks and biographies also have an ISBN, a title, and a publishing year. Additionally, they have more specific features such as the attribute subjectArea for textbooks and the attribute about for biographies. Consequently, in the figure below, we introduce the object types TextBook and Biography by specializing the object type Book. As a result, TextBook and Biography are subtypes of Book.

Get hands-on with 1200+ tech skills courses.