 // Purpose.  Adapter
 //
 // Discussion.  The Adapter pattern
 // discusses how to "wrap" the old in-
 // terface of a legacy component, so
 // that it can continue to contribute
 // in a new system.  It is about "im-   #include <iostream.h>
 // pedance matching" an old dog with    #include <stdio.h>
 // new tricks (to mix metaphors).  On   #include <time.h>
 // the left, WimpyTime "hasa" in-
 // stance of the legacy component,      class ManlyTime {
 // and delegates the "heavy lifting"    public:
 // to it.  On the right, private           char* getTime() {
 // derivation is used to accomplish           static char buf[30];
 // the same result.                           time_t  lt;
                                               tm*     ltStruct;
 class ManlyTime {                             time( &lt );
 public:                                       ltStruct = localtime(&lt);
    char* getTime() {                          strftime( buf, 30, "%H%M",
       static char buf[30];                       ltStruct );
       time_t  lt;                             return buf;
       tm*     ltStruct;                    }
       time( &lt );                      };
       ltStruct = localtime(&lt);
       strftime( buf, 30, "%H%M",        class WimpyTime :
          ltStruct );                              private ManlyTime {
       return buf;                       public:
    }                                       char* getTime() {
 };                                            static char buf[30];
                                               char *ptr, mi[3], am[3];
 class WimpyTime {                             int  hr;
 public:                                       ptr = ManlyTime::getTime();
    char* getTime() {                          cout << "old interface time is "
       static char buf[30];                       << ptr << endl;
       char *ptr, mi[3], am[3];                strcpy( mi, &(ptr[2]) );
       int  hr;                                ptr[2] = '\0';
       ptr = imp_.getTime();                   sscanf( ptr, "%d", &hr );
       cout << "old interface time is "        strcpy( am, "AM" );
          << ptr << endl;                      if (hr > 12) {
       strcpy( mi, &(ptr[2]) );                   hr -= 12;
       ptr[2] = '\0';                             strcpy( am, "PM" ); }
       sscanf( ptr, "%d", &hr );               sprintf( buf, "%d:%s %s",
       strcpy( am, "AM" );                        hr, mi, am );
       if (hr > 12) {                          return buf;
          hr -= 12;                         }
          strcpy( am, "PM" ); }          };
       sprintf( buf, "%d:%s %s",
          hr, mi, am );                  void main( void )
       return buf;                       {
    }                                       WimpyTime  newT;
 private:                                   char*      ptr;
    ManlyTime  imp_;                        ptr = newT.getTime();
 };                                         cout << "new interface time is "
                                               << ptr << endl;
 void main( void )                       }
 {
    WimpyTime  newT;                     // old interface time is 1721
    char*      ptr;                      // new interface time is 5:21 PM
    ptr = newT.getTime();
    cout << "new interface time is "
       << ptr << endl;
 }

 // old interface time is 1709
 // new interface time is 5:09 PM

