iOS design mode-bridging
Description
1. Bridging mode to separate the abstract hierarchy from the implementation, so that it can be changed independently, the abstraction layer defines the upper layer of abstraction interface for the client to use, the implementation of the hierarchy defined for the level of abstraction for the use of the underlying interface, the implementation of the class reference is encapsulated in an instance of the abstraction layer, bridging is formed.
2. Bridging mode solves a functional architecture that is functionally similar but not identical, in order to make the implementation more flexible.
Source
Https://github.com/YouXianMing/BridgePattern
////ConsoleController.h//GameBoy////Created by youxianming on 15/7/26.//Copyright (c) 2015 youxianming. All rights reserved.//#import<Foundation/Foundation.h>#import "ConsoleEmulator.h"@interfaceConsolecontroller:nsobject/** Abstract Simulator*/@property (nonatomic, strong) Consoleemulator*emulator;/** * Execute command * * @param command 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"@interfaceConsolecontroller:nsobject/** Abstract Simulator*/@property (nonatomic, strong) Consoleemulator*emulator;/** * Execute command * * @param command 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>typedefenum: Nsuinteger {kconsolecommandup, Kconsolecommanddown, Kconsolecommandleft, Kconsolecommandright, Kconsolecommandselect, Kconsolecommandstart, KConsoleCommandAction1, KConsoleCommandAction2,} Console Command;@interfaceConsoleemulator:nsobject/** * Load Command * * @param command command*/- (void) Loadinstructionsforcommand: (consolecommand) command;/** * Execution Instructions*/- (void) excuteinstructions;@end
////CONSOLEEMULATOR.M//GameBoy////Created by youxianming on 15/7/26.//Copyright (c) 2015 youxianming. All rights reserved.//#import "ConsoleEmulator.h"@implementationConsoleemulator- (void) Loadinstructionsforcommand: (consolecommand) Command {//Subclass Overloading Implementation}- (void) excuteinstructions {//Subclass Overloading Implementation}@end
Analysis
Bridge Mode Ethics Map
In fact, it is an abstract management class that manages an abstract execution class, with a method or methods to let the abstract perform the function of the class, which is the legendary bridging pattern
iOS design mode-bridging