Objective-C 面板模式--簡單介紹和使用

來源:互聯網
上載者:User

標籤:外觀   div   int   重要   control   樣本   耦合   建立   開發   

面板模式(Facade),為子系統中的一組介面提供一個一致的介面,定義一個高層介面,這個介面使得這一子系統更加容易使用。

 

在以下情況下可以考慮使用面板模式:(1)設計初期階段,應該有意識的將不同層分離,層與層之間建立面板模式。(2) 開發階段,子系統越來越複雜,增加面板模式提供一個簡單的調用介面。(3) 維護一個大型遺留系統的時候,可能這個系統已經非常難以維護和擴充,但又包含非常重要的功能,為其開發一個外觀類,以便新系統與其互動。 有點:(1)實現了子系統與用戶端之間的松耦合關係。(2)用戶端屏蔽了子系統組件,減少了用戶端所需處理的對象數目,並使得子系統使用起來更加容易。 簡單程式碼範例:建立一個Group包含`Shape.h / Shape.m / RectShape.h / RectShape.m / CircleShape.h / CircleShape.m Shape.h
1 #import <Foundation/Foundation.h>2 3 @interface Shape : NSObject4 5 - (void)draw;6 7 @end

 

RectShape.h

1 #import "Shape.h"2 3 @interface RectShape : Shape4 5 - (void)draw;6 7 @end

 

CircleShape.h

1 #import "Shape.h"2 3 @interface RectShape : Shape4 5 - (void)draw;6 7 @end

 

再建立一個DrawShape.h / DrawShape.m作為Controller使用

 1 #import <Foundation/Foundation.h> 2 #import "RectShape.h" 3 #import "CircleShape.h" 4  5 @interface DrawShape : NSObject 6  7 + (void)drawRectShape; 8 + (void)drawCircleShape; 9 10 @end

 

Controller中使用

 1 #import "ViewController.h" 2 #import "DrawShape.h" 3  4 @interface ViewController () 5  6 @end 7  8 @implementation ViewController 9 10 - (void)viewDidLoad {11     [super viewDidLoad];12     13     //調用畫畫介面14     [DrawShape drawRectShape];15     [DrawShape drawCircleShape];16     17 }18 19 20 @end

 

 

 

Objective-C 面板模式--簡單介紹和使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.