iOS design mode-builder
Schematic diagram
Description
1. The process of building complex objects into one module, guided by a unified guide to the construction of objects called the generator pattern
2. Builder mode is suitable for building grouped objects
Source
Https://github.com/YouXianMing/BuilderPattern
////CarBuilder.h//Builderpattern////Created by youxianming on 15/9/14.//Copyright (c) 2015 youxianming. All rights reserved.//#import<Foundation/Foundation.h>@interfaceCarbuilder:nsobject {nsmutabledictionary*_carinfo;}/** * Car information*/@property (nonatomic, Strong,ReadOnly) Nsdictionary *car;/** * Build Wheels*/- (void) Buildwheel;/** * Build engine*/- (void) Buildengine;/** * Construction Shell*/- (void) Buildshell;@end
////CARBUILDER.M//Builderpattern////Created by youxianming on 15/9/14.//Copyright (c) 2015 youxianming. All rights reserved.//#import "CarBuilder.h"@interfaceCarbuilder ()@end@implementationCarbuilder-(instancetype) init { self=[Super Init]; if(self) {_carinfo=[[Nsmutabledictionary alloc] init]; } returnSelf ;}- (void) Buildwheel {_carinfo[@"Wheel"] =@"Normal_wheel";}- (void) Buildengine {_carinfo[@"engine"] =@"Normal_engine";}- (void) Buildshell {_carinfo[@"Shell"] =@"Normal_shell";}@synthesizeCar =_car;-(Nsdictionary *) Car {return[[Nsdictionary alloc] initwithdictionary:_carinfo];}@end
// // BMWBuilder.h// builderpattern//// Created by Youxianming on 15/9/14. // Copyright (c) 2015 youxianming. All rights reserved. // #import " CarBuilder.h " @interface Bmwbuilder:carbuilder @end
////BMWBUILDER.M//Builderpattern////Created by youxianming on 15/9/14.//Copyright (c) 2015 youxianming. All rights reserved.//#import "BMWBuilder.h"@implementationBmwbuilder- (void) Buildwheel {_carinfo[@"Wheel"] =@"Bmo_wheel";}- (void) Buildengine {_carinfo[@"engine"] =@"Bmo_engine";}- (void) Buildshell {_carinfo[@"Shell"] =@"Bmo_shell";}@end
////VIEWCONTROLLER.M//Builderpattern////Created by youxianming on 15/9/14.//Copyright (c) 2015 youxianming. All rights reserved.//#import "ViewController.h"#import "CarBuilder.h"#import "BMWBuilder.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Carbuilder*builder =[[Carbuilder alloc] init]; [Builder Buildengine]; [Builder Buildshell]; [Builder Buildwheel]; NSLog (@"%@", Builder.car); Carbuilder*bmwbuilder =[[Bmwbuilder alloc] init]; [Bmwbuilder Buildengine]; [Bmwbuilder Buildshell]; [Bmwbuilder Buildwheel]; NSLog (@"%@", Bmwbuilder.car);}@end
Analysis
Relationship Ethics Chart
iOS design mode-builder