The implementation of the M_Dog class is similar to the implementation of the Dog class. However, DOGMETA.C is also a client of the Dog class; CreateADog returns a pointer to an instance of the Dog class.

The final implementation of the new Dog class is identical to the previous example. However, clients of the Dog class instantiate instances of the Dog class differently, as shown in the following sample code:

/*
 *  DogMMain.C - Another client C program to manipulate a Dog object
 */

/* Makes compile go faster for non-PM programs */
#define INCL_NOPMAPI
#define INCL_DOSERRORS
#define INCL_DOS

#include <os2.h>
/* Include declarations for Dog and M_Dog */
#include "dogmeta.h"

int main(VOID)
{
  Dog  *Zack;

  /*
   * Create the Dog class and save a pointer to it.
   */

  M_Dog *DogClassObj;
  DogClassObj = DogNewClass(Dog_MajorVersion, Dog_MinorVersion);
  Zack = _CreateADog(DogClassObj);
  __set_breed(Zack, "Yorkshire Terrier");
  _display(Zack);
  _somFree(Zack);
  return NO_ERROR;
}

The constructor method, that is, the method that creates instances of an object, for the Dog class is now CreateADog. In the previous examples, the DogNew macro was used to instantiate Dog objects. Because the DogNew macro invokes DogNewClass to create the Dog class object, the previous client programs did not have to invoke DogNewClass directly. Because the implementation of CreateADog does not call DogNewClass, the new client program is required to do so.

The parameters for DogNewClass are defined by the class implementer in the DOGMETA.IDL file. MajorVersion and MinorVersion are attributes defined in the attribute section of the IDL file and used by DogNewClass to determine compatibility with versions of the class library.


[Back] [Next]