Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Class Hierarchy

The C# class hierarchy which is used to represent the basic repertoire of abstract data types is shown in Figure gif. Two kinds of classes are shown in Figure gif; abstract C# classes , which look like this tex2html_wrap60433, and concrete C# classes , which look like this tex2html_wrap60435. In addition, C# interfaces  are shown like this tex2html_wrap60437. Solid lines in the figure indicate the specializes  relation between classes and between interfaces; base classes and interfaces always appear to the left of derived classes and interfaces. Dashed lines indicates the the realizes  relation between a class and the interface(s) it implements. In C# a class may specialize at most one other class and it may realize any number of interfaces. A C# interface may specialize any number of interfaces (but not classes).

   figure4263
Figure: Object class hierarchy.

A C# interface  comprises a set of method and property declarations . An interface does not supply implementations  for the methods or properties it declares. In effect, an interface identifies the set of operations provided by every class that implements  the interface.

An abstract class  in C# is a class which defines only part of an implementation. Consequently, it is not possible create object instances of abstract classes. In C# an abstract class may contain zero or more abstract methods  or abstract properties . A abstract method or property is one for which no implementation is given.

An abstract class is intended to be used as the base class  from which other classes are derived . By declaring abstract methods in the base class, it possible to access the implementations provided by the derived classes through the base-class methods. Consequently, we don't need to know how a particular object instance is implemented, nor do we need to know of which derived class it is an instance.

This design pattern uses the idea of polymorphism . Polymorphism literally means ``having many forms.'' The essential idea is that a C# interface is used to define the set of values and the set of operations--the abstract data type. Then, various different implementations (many forms) of the interface can be made. We do this by defining abstract classes that contain shared implementation features and then by deriving concrete classes from the abstract base classes.

The remainder of this section presents the top levels of the class hierarchy which are shown in Figure gif. The top levels define those attributes of objects which are common to all of the classes in the hierarchy. The lower levels of the hierarchy are presented in subsequent chapters where the abstractions are defined and various implementations of those abstractions are elaborated.

   figure4294
Figure: Object class hierarchy.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.