Example 5-Using Multiple Inheritance

The "Hello" class is useful for writing messages to the screen. So that clients can also write messages to printers and disk files, this example references two additional classes: "Printer" and "Disk." The "Printer" class will manage messages to a printer, and the "Disk" class will manage messages sent to files. These classes can be defined as follows:

   #include <somobj.idl>

   interface Printer : SOMObject
   {
       void stringToPrinter(in string s) ;
        // This method writes a string to a printer.
   };

   #include <somobj.idl>

   interface Disk : SOMObject
   {
        void stringToDisk(in string s) ;
        // This method writes a string to disk.
   };

This example assumes the "Printer" and "Disk" classes are defined separately (in "print.idl" and "disk.idl," for example), are implemented in separate files, and are linked with the other example code. Given the implementations of the "Printer" and "Disk" interfaces, the "Hello" class can use them by inheriting from them, as illustrated next.

     Initial Message
     Initial Message               - goes to a Printer

     Initial Message               - goes to Disk

This tutorial has described features of SOM IDL that will be useful to C and C++ programmers. SOM IDL also provides features such as full type checking, constructs for declaring private methods, and constructs for defining methods that receive and return pointers to structures. Chapter 4, "SOM IDL and the SOM Compiler" gives complete description of the SOM IDL syntax and also describes how to use the SOM Compiler. In addition, Chapter 5, "Implementing Classes in SOM," provides helpful information for completing the implementation template, for using initializer (somDefaultInit or user-defined initialization methods), for defining SOM class libraries, and for customizing various aspects of SOMobjects execution.


[Back: Example 4 - Initializing a SOM Object]
[Next: Using SOM Classes in Client Programs]