設計模式之- 面板模式(Facade Pattern)

來源:互聯網
上載者:User

標籤:design   對象   使用   awr   設計   pattern   面板模式   類圖   pac   

面板模式面板模式(Facade Pattern):外部與一個子系統的通訊必須通過一個統一的外觀對象進行,為子系統中的一組介面提供一個一致的介面,面板模式定義了一個高層介面,這個介面使得這一子系統更加容易使用。面板模式又稱為門面模式,它是一種對象結構型模式。 C++代碼:
#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;}

類圖:

面板模式感覺最簡單了,相當於把幾個獨立的介面寫了一個統一的封裝類進行了合并,並向外提供統一的調用介面,代碼一看便知!

設計模式之- 面板模式(Facade Pattern)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.