博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS设计模式 - 外观
阅读量:7065 次
发布时间:2019-06-28

本文共 1649 字,大约阅读时间需要 5 分钟。

iOS设计模式 - 外观

 

原理图

 

 

说明

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

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

 

源码

////  ShapeMaker.h//  FacadePattern////  Created by YouXianMing on 15/7/28.//  Copyright (c) 2015年 YouXianMing. All rights reserved.//#import 
#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 
@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

分析

详细对比示意图

转载地址:http://wgall.baihongyu.com/

你可能感兴趣的文章
通过Spring Boot中的手动Bean定义提高启动性能
查看>>
再次简单明了总结flex布局,一看就懂...
查看>>
一步步学会用docker部署应用(nodejs版)
查看>>
无root权限新建git仓库进行多人协同工作
查看>>
【跃迁之路】【687天】程序员高效学习方法论探索系列(实验阶段444-2019.1.6)...
查看>>
假装用某米赛尔号的角度看Python面向对象编程
查看>>
RGBA和OPACITY的区别&DISPLAY和VISIBILITY的区别
查看>>
膨胀的template class成员函数
查看>>
Flask之flask-mail邮件发送
查看>>
Immutable
查看>>
要提高团队代码质量,就要这么用Git进行版本控制!
查看>>
[LeetCode] 702. Search in a Sorted Array of Unknown Size
查看>>
常用的ES6
查看>>
高级 Vue 组件模式 (5)
查看>>
Nginx负载均衡配置及策略
查看>>
Node 框架接入 ELK 实践总结
查看>>
julia学习笔记:元编程-表达式
查看>>
vector中erase的用法
查看>>
redux, koa, express 中间件实现对比解析
查看>>
vue动态绑定图片和背景图
查看>>