• 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

    分析

    详细对比示意图

  • 相关阅读:
    WebGoat之Injection Flaws
    WebGoat之Web Services
    XPath语法
    用Maven在Eclipse中配置Selenium WebDriver——方法1
    用Maven在Eclipse中配置Selenium WebDriver——方法2
    Enum与enum名字相互转换
    数据库数据类型varchar(n)与nvarchar(n)比较
    网页切图工具
    Html标签
    在VS的Solution Explorer中高亮当前编辑的文件
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4684233.html
Copyright © 2020-2023  润新知