zoukankan      html  css  js  c++  java
  • iOS设计模式

    iOS设计模式 - 桥接

    示意图

    说明

    1. 桥接模式为把抽象层次结构从实现中分离出来,使其可以独立变更,抽象层定义了供客户端使用的上层抽象接口,实现层次结构定义了供抽象层次使用的底层接口,实现类的引用被封装于抽象层的实例中,桥接就形成了.

    2. 桥接模式可以解决具有功能类似但又不完全相同的某种功能架构,为了能让实现更加灵活.

    复制代码
    //
    //  ConsoleController.h
    //  GameBoy
    //
    //  Created by YouXianMing on 15/7/26.
    //  Copyright (c) 2015年 YouXianMing. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "ConsoleEmulator.h"
    
    @interface ConsoleController : NSObject
    
    /**
     *  抽象模拟器
     */
    @property (nonatomic, strong) ConsoleEmulator  *emulator;
    
    /**
     *  执行指令
     *
     *  @param command 指令
     */
    - (void)excuteCommand:(ConsoleCommand)command;
    
    @end
    复制代码
    复制代码
    //
    //  ConsoleController.h
    //  GameBoy
    //
    //  Created by YouXianMing on 15/7/26.
    //  Copyright (c) 2015年 YouXianMing. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "ConsoleEmulator.h"
    
    @interface ConsoleController : NSObject
    
    /**
     *  抽象模拟器
     */
    @property (nonatomic, strong) ConsoleEmulator  *emulator;
    
    /**
     *  执行指令
     *
     *  @param command 指令
     */
    - (void)excuteCommand:(ConsoleCommand)command;
    
    @end
    复制代码
    复制代码
    //
    //  ConsoleEmulator.h
    //  GameBoy
    //
    //  Created by YouXianMing on 15/7/26.
    //  Copyright (c) 2015年 YouXianMing. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    typedef enum : NSUInteger {
        
        kConsoleCommandUp,
        kConsoleCommandDown,
        kConsoleCommandLeft,
        kConsoleCommandRight,
        
        kConsoleCommandSelect,
        kConsoleCommandStart,
        
        kConsoleCommandAction1,
        kConsoleCommandAction2,
        
    } ConsoleCommand;
    
    @interface ConsoleEmulator : NSObject
    
    /**
     *  加载指令
     *
     *  @param command 指令
     */
    - (void)loadInstructionsForCommand:(ConsoleCommand)command;
    
    /**
     *  执行指令
     */
    - (void)excuteInstructions;
    
    @end
    复制代码
    复制代码
    //
    //  ConsoleEmulator.m
    //  GameBoy
    //
    //  Created by YouXianMing on 15/7/26.
    //  Copyright (c) 2015年 YouXianMing. All rights reserved.
    //
    
    #import "ConsoleEmulator.h"
    
    @implementation ConsoleEmulator
    
    - (void)loadInstructionsForCommand:(ConsoleCommand)command {
        
        // 由子类重载实现
    }
    
    - (void)excuteInstructions {
        
        // 由子类重载实现
    }
    
    @end
    复制代码

    分析

    桥接模式伦理图

    其实,就是抽象的管理类管理一个抽象的执行类,通过一个方法或者多个方法来让抽象执行类完成功能,这就是传说中的桥接模式

  • 相关阅读:
    Codeforces Round #719 (Div. 3) 题解
    Codeforces Global Round 14 A~F题解
    AtCoder Beginner Contest 199 题解
    Codeforces Round #716 (Div. 2) A~D 题解
    Codeforces Round #713 (Div. 3) 题解
    Codeforces Round #712 (Div. 2) A~E 题解
    CodeCraft-21 and Codeforces Round #711 (Div. 2) A~E 题解
    CF839 D 莫比乌斯反演
    java存大数和高精度浮点数(BigInteger与BigDecimal)
    java科学计算常用方法(Math)
  • 原文地址:https://www.cnblogs.com/ming1025/p/6654989.html
Copyright © 2011-2022 走看看