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

    分析

    详细对比示意图

  • 相关阅读:
    作为一个新手程序员,该如何去挽救一个失败的项目?
    IOS查看APP的crash Log
    UITableView 性能优化(卡问题自检)
    ARC学习笔记(一)
    iPhone的UDID与push中使用的device token的关系
    跳转appstore的评分页面和软件的首页
    IOS项目Jenkins集成脚本举例
    jenkins集成学习心得
    学习设计模式心得
    网页跳转到APP
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4684233.html
Copyright © 2011-2022 走看看