home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 8-5.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  858b  |  41 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. class Class {
  7. public:
  8.     virtual Class *make(const char*,EmployeeID);
  9.     // . . . .
  10. };
  11.  
  12. class Employee:  public Class {
  13. public:
  14.     Class *make(const char*, EmployeeID);
  15.     // . . . .
  16. };
  17.  
  18. Employee *employeeExemplar = new Employee(Exemplar());
  19.  
  20. class VicePresident: public Employee {
  21.     // . . . .
  22. };
  23.  
  24. class LineWorker:  public Employee {
  25.     // . . . .
  26. };
  27.  
  28. Class *
  29. Employee::make(const char *name, EmployeeID id)
  30. {
  31.     Class *retval = 0;
  32.     switch (id.firstChar()) {
  33.     case 'M':    retval = new Manager(name, id);
  34.                  break;
  35.     case 'V':    retval = new VicePresident(name, id);
  36.                  break;
  37.     // . . . .
  38.     }
  39.     return retval;
  40. }
  41.