标签:design 对象 使用 awr 设计 pattern 外观模式 类图 pac
#include<iostream> using namespace std; class Shape { public: virtual void draw()=0; }; class Rectangle : public Shape { public: void draw() { cout<<"Rectangle::draw()"<<endl; } }; class Square : public Shape { public: void draw() { cout<<"Square ::draw()"<<endl; } }; class Circle : public Shape { public: void draw() { cout<<"Circle ::draw()"<<endl; } }; class ShapeMaker { Shape *circle; Shape *rectangle; Shape *square; public: ShapeMaker() { circle = new Circle(); rectangle = new Rectangle(); square = new Square(); } void drawCircle(){ circle->draw(); } void drawRectangle(){ rectangle->draw(); } void drawSquare(){ square->draw(); } }; class FacadePatternDemo { public: static void method(int argc,char**argv) { ShapeMaker *shapeMaker = new ShapeMaker(); shapeMaker->drawCircle(); shapeMaker->drawRectangle(); shapeMaker->drawSquare(); } }; int main(int argc,char**argv){ FacadePatternDemo::method(argc,argv); return 0; }
类图:
外观模式感觉最简单了,相当于把几个独立的接口写了一个统一的包装类进行了合并,并向外提供统一的调用接口,代码一看便知!
标签:design 对象 使用 awr 设计 pattern 外观模式 类图 pac
原文地址:https://www.cnblogs.com/J1ac/p/9738379.html