3. Subtypes and Derived types

The typing mechanism in Ada is characterised by a set of values and a set of operations. Here we could illustrate with examples how subtype and derived type declarations contribute to reuse existing components or type abstractions. In other words, it is known as " Type inheritance ". A subtype declaration supports to reuse existing types, and a derived type supports to resue existing types and operations. See the following examples.

Type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); -- Type declaration

Subtype Weekday is Day range Mon .. Fri; -- Subtype of a type

Type Midweek is new Day range Tue .. Thu; -- Derived type

Guideline1 : Where possible prefer to define subtype and derived type than to redefine a type.