標籤:
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設計模式 - 外觀