iOS设计模式 - 外观

iOS设计模式 - 外观

 

原理图

 

 

说明

1. 当客服端需要使用一个复杂的子系统(子系统之间关系错综复杂),但又不想和他们扯上关系时,我们需要单独的写出一个类来与子系统交互,隔离客户端与子系统之间的联系,客户端只与这个单独写出来的类交互

2. 外观模式实质为为系统中的一组接口提供一个统一的接口,外观定义了一个高层接口,让子系统易于使用

 

源码

https://github.com/YouXianMing/iOS-Design-Patterns

//
//  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

分析

详细对比示意图


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值