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

subobjects

The most common way of reusing existing classes in new classes is to instantiate members of the existing classes in the new class. The instantiated member is referred to as a subobject. The object has to be created in the object_create method of the new class. The object exists locally as a subobject of the new object. This means commands and methods can be executed on the subobject. Thereby allowing the new class to profit from the existing classes implementation without knowing any of the details of implementation.

To execute commands locally use the convenience function dev_cmd(). Syntax for dev_cmd is -

long dev_cmd (short cmd, DevArgument *argin_ptr, DevType in_type,
              DevArgument *argout_ptr, DevType out_type, long *error);

It is also possible to use remote devices as subobjects in a class by importing them (as opposed to creating them locally). This has the advantage that a new class can use existing classes across the network i.e. it is not obliged to be on the same physical machine as the imported device. It has the disadvantage that executing commands on the remote device takes longer because of the network overhead. Another disadvantage of this method is that methods cannot be executed remotely. Nonetheless it can be very useful sometimes to import devices in classes and it is done quite often.



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