//13.6 系统扩展(System Extension)
//13.6.1 新添加一个界面(Adding One Interface)
//添加一个sony2.h 做为调整亮度的操作,他继承者sony.h
//由Sony派生Sony2
#include "createsony.h" #include "sony.h" enum Technology{PUREFLAT,PLASMA,LIQUIDCRYSTAL}; void fn(Sony* s) { Sony2 * ps2 = dynamic_cast<Sony2*>(s); //增加 if(ps2) ps2->adjustLight(); //否则不用 ps2->adjustVolume(); ps2->switchChannel(); } void createSonyObject(CreateSony* sp) { Sony* s29 = createSonyInch29(sp); fn(s29); delete s29; } #include <iostream> using namespace std; int main() { if(CreateSony* sp = createCreateSony(LIQUIDCRYSTAL)){ createSonyObject(sp); delete(sp); } system("pause"); return 0; }
#ifndef HEADER_SONY2 #define HEADER_SONY2 #include "sony.h" class Sony2 : public Sony { public: virtual void adjustLight() =0; }; #endif;/**/