AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Articles >
Ada FAQ >
Getting Started >
Home >
Books & Tutorials >
Source Treasury >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
What does Class mean in Ada95 (Matthew Heaney)

A "class" in Ada denotes a family of types.

For tagged types, the type T'Class denotes the type T and all its
descendents.

So if I have this hierarchy:

  type T is tagged private;

     type U is new T with private;

         type W is new U with private;

     type V is new T with private;


An object of "class-wide" type T'Class can be any of the "specific" types T,
U, V, or W.

An object of class-wide type U'Class can be any of the specific types U
or W.

This distinction is nice, because it allows you to see explicitly when
you have a specific type (T), or a type and any of its descents
(T'Class).  It makes it obvious that procedures like:

  procedure Print (Stack : in Stack_Type'Class);

are intended to work for Stack_Type and any type that derives from
Stack_Type.  

Print is not a primitive operation of type Stack_Type, and therefore
doesn't get inherited during derivations from Stack_Type.  There is one
and only one Print operation, and it works for any kind of stack (that
is, those that derive from stack, i.e. in Stack_Type'Class).

But if I see this:

  function Is_Full (Stack : in Bounded_Stack) return Boolean;

then I know that Is_Full is only intended to take an object of
(specific) type Bounded_Stack.  A stack that derives from Bounded_Stack
would indeed inherit operation Is_Full.

T'Class is a "class-wide" type, which denotes a family of "specific"
types: type T, and any type that derives from T.


(c) 1998-2004 All Rights Reserved David Botton