zoukankan      html  css  js  c++  java
  • 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(@"
    ");
    }
    
    + (void)drawCircleAndSquare {
    
        Shape *circle    = [Circle new];
        Shape *square    = [Square new];
        
        [circle draw];
        [square draw];
        NSLog(@"
    ");
    }
    
    + (void)drawAll {
    
        Shape *circle    = [Circle new];
        Shape *rectangle = [Rectangle new];
        Shape *square    = [Square new];
        
        [circle draw];
        [rectangle draw];
        [square draw];
        NSLog(@"
    ");
    }
    
    @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

    分析

    详细对比示意图

  • 相关阅读:
    XE8下安装IntraWeb 14.0.40和D7下安装IntraWeb 11.0.63破解版的正确方法
    网易博客打不开怎么办
    SQL SERVER 导入EXCEL的存储过程
    TMemoryStream、String与OleVariant互转
    【转载】Delphi Idhttp的get和post方法
    sqlserver得到行号
    Delphi 中的 XMLDocument 类详解(5)
    10款免费且开源的项目管理工具
    iOS开发者必备:九大设计类工具
    15个步骤创立技术公司,并收获千万用户(完结)
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4684233.html
Copyright © 2011-2022 走看看