 // Purpose.  Bridge                     class DateImp;
 //
 // Discussion.  Even though Date has    class Date {
 // a clean interface and a well encap-  public:
 // sulated implementation, the client      Date( int y, int m, int d );
 // still has to recompile if the class     ~Date();
 // architect changes his/her mind.         void output();
 // Instead, create a wrapper (or inter-    static void setImp( char* t ) {
 // face) class that contains and dele-        strcpy( impType_, t ); }
 // gates to a body (or implementation)  private:
 // class.  Client can now specify at       DateImp*    rep_;
 // run-time exactly what s/he wants.       static char impType_[10];
                                         };
 #include <iostream.h>                   char Date::impType_[] = "Ok";
 #include <stdio.h>
                                         class DateImp { public:
 class Date {                               virtual void output() = 0;
                                         };
 public:
    Date( int y, int m, int d );         class DateOk : public DateImp {
    void output();                       public:
                                            DateOk( int y, int m, int d );
 private:                                   void output();
                                         private:
 #ifdef OK                                  int  year_, month_, day_;
    int  year_, month_, day_;            };
 #endif
                                         class DateAA : public DateImp {
 #ifdef AA                               public:
    int        toJulian(int,int,int);       DateAA( int y, int m, int d );
    char*      fromJulian(void);            void output();
    int        julian_;                  private:
    int        year_;                       int        toJulian(int,int,int);
    static int dayTable_[2][13];            char*      fromJulian(void);
 #endif                                     int        julian_;
                                            int        year_;
 };                                         static int dayTable_[2][13];
                                         };
 #ifdef OK
 void Date::output() {                   Date::Date( int y, int m, int d ) {
    char buf[20];                           if ( ! strcmp( impType_, "Ok" ))
    int year = year_ - (year_/100*100);        rep_ = new DateOk( y, m, d );
    sprintf( buf, "%02d%02d%02d",           else
       year, month_, day_ );                   rep_ = new DateAA( y, m, d );
    cout << buf << "  "; }               }
 #endif                                  Date::~Date()       { delete rep_; }
                                         void Date::output() { rep_->output(); }
 #ifdef AA
 void Date::output() {                   #include "bridge2.inc"
    cout << fromJulian() << "  "; }
 #endif                                  void main( void )
                                         {
 #include "bridge1.inc"                     Date  d1( 1996, 2, 29 );
                                            Date  d2( 1996, 2, 30 );
 void main( void )                          Date::setImp( "AA" );
 {                                          Date  d3( 1996, 2, 29 );
    Date  d1( 1996, 2, 29 );                Date  d4( 1996, 2, 30 );
    Date  d2( 1996, 2, 30 );                d1.output();  d2.output();
    d1.output();                            cout << endl;
    d2.output();                            d3.output();  d4.output();
    cout << endl;                           cout << endl;
 }                                       }

 // 960229  960230                       // 960229  960230
 // 960229  960301                       // 960229  960301

