next up previous contents
Next: superclasses Up: Using Classes Previous: classes

subclasses

In OIC a class can have as many subclasses as it wants. Each class defines a hierarchy. A hierarchy is composed of a root class and all subsequent classes up to the final class. Because in OIC each class can only belong to one superclass, class hierarchies in OIC are one dimensional tree structures (other languages like C++ for example, support multiple inheritance and are therefore two dimensional tree structures). Figure 3 represents a typical OIC tree structure.

The first step in implementing a subclass is to specify its requirements. Subclasses are implemented by modifying the definition of the superclass (defined in the superclasses private include file). A definition is required for the partial object and class record structures. The partial object record structure contains those variables and constants which each member of the new class requires a personal copy thereof. The partial class structure contains those variables and constants which are required for the implementation of the class and which can be shared by all members of the class. The classes object and class record structures contain the full description of the class hierarchy. They are formed by adding the partial object and class record structures to the object and class record structures respectively of the superclass.

Once the class and object structures of the subclass are defined then the class behaviour can be implemented in the source file. This means implementing the minimum methods required by each class (e.g. class_initialise)plus the new methods which the new subclass requires. If the new subclass will be instantiated then it will also implement a list of device server commands.

It is necessary that each subclass initialises the root class (DevServerClass) class structure with at least the superclass pointer ( superclass_pointer) in order for OIC to work. This is done in the DevMethodClassInitialise method implementation. The classes partial class structure is also initialised in the DevMethodClassInitialise method.

One very important implementation detail of OIC is that because it is only a programming technique and not a compiler a certain amount of redundancy exists which could confuse the beginner device server programmer. The class record definition includes the partial class record structures for the root class, all superclasses and the class itself. Because the superclasses do not know about the subclasses it is impossible for them to initialise 'their' partial class structures of each of their subclasses. Consequently the partial classes structures of the superclasses of a subclasses remain uninitialised. This (possibly confusing for beginner programmers) aspect has been retained in the OIC model for two reasons :

  1. to provide better readability of the class record structure definition in the private include file, and
  2. to maintain symmetry with the object record structure definition.

If the class needs to access data in one of its superclasses it should do so by following the superclasses class_pointer in the root class partial structure and thereby access the initialised copy of the superclasses partial structure.

The same doesn't apply to the object record structure however. Each object has its own private copy of the object record. A subclass can access the data defined in the superclasses object partial structure directly. All object data is accessible this way. This is because OIC does not distinguish between private and public data.



next up previous contents
Next: superclasses Up: Using Classes Previous: classes



Andy Goetz
Tue Jan 28 13:58:13 MET 1997