iOS設計模式 - 外觀

來源:互聯網
上載者:User

標籤:

iOS設計模式 - 外觀

 

原理圖

 

 

說明

1. 當客服端需要使用一個複雜的子系統(子系統之間關係錯綜複雜),但又不想和他們扯上關係時,我們需要單獨的寫出一個類來與子系統互動,隔離用戶端與子系統之間的聯絡,用戶端只與這個單獨寫出來的類互動

2. 面板模式實質為為系統中的一組介面提供一個統一的介面,外觀定義了一個高層介面,讓子系統便於使用

 

源碼

https://github.com/YouXianMing/FacadePattern

////  ShapeMaker.h//  FacadePattern////  Created by YouXianMing on 15/7/28.//  Copyright (c) 2015年 YouXianMing. All rights reserved.//#import <Foundation/Foundation.h>#import "Shape.h"#import "Circle.h"#import "Rectangle.h"#import "Square.h"@interface ShapeMaker : NSObject+ (void)drawCircleAndRectangle;+ (void)drawCircleAndSquare;+ (void)drawAll;@end
////  ShapeMaker.m//  FacadePattern////  Created by YouXianMing on 15/7/28.//  Copyright (c) 2015年 YouXianMing. All rights reserved.//#import "ShapeMaker.h"@implementation ShapeMaker+ (void)drawCircleAndRectangle {    Shape *circle    = [Circle new];    Shape *rectangle = [Rectangle new];        [circle draw];    [rectangle draw];    NSLog(@"\n");}+ (void)drawCircleAndSquare {    Shape *circle    = [Circle new];    Shape *square    = [Square new];        [circle draw];    [square draw];    NSLog(@"\n");}+ (void)drawAll {    Shape *circle    = [Circle new];    Shape *rectangle = [Rectangle new];    Shape *square    = [Square new];        [circle draw];    [rectangle draw];    [square draw];    NSLog(@"\n");}@end
////  Shape.h//  FacadePattern////  Created by YouXianMing on 15/7/28.//  Copyright (c) 2015年 YouXianMing. All rights reserved.//#import <Foundation/Foundation.h>@interface Shape : NSObject/** *  繪製 */- (void)draw;@end
////  Shape.m//  FacadePattern////  Created by YouXianMing on 15/7/28.//  Copyright (c) 2015年 YouXianMing. All rights reserved.//#import "Shape.h"@implementation Shape- (void)draw {    // 由子類重寫}@end

 

分析

詳細對比

 

iOS設計模式 - 外觀

聯繫我們

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