iOS design mode-builder
Schematic diagram
Description
The generator pattern can be understood as a component assembly plant, very similar to the factory Method!
vehiclebuilder.h// builderpattern//// Created by youxianming on 15/8/18.// Copyright (c) 2015 Youxianming. All rights reserved.//#import <Foundation/Foundation.h> #import "VehicleBuilderProtocol.h" @interface Vehiclebuilder:nsobject <vehiclebuilderprotocol>/** * Vehicle information */@property (nonatomic, Strong) Nsmutabledictionary *vehicleinfo; @end
vehiclebuilder.m//builderpattern////Created by youxianming on 15/8/18.//Copyright (c) 2015 youxianming. All rights reserved.//#import ' VehicleBuilder.h ' @implementation vehiclebuilder-(instancetype) init {self = [super INIT]; if (self) {self.vehicleinfo = [nsmutabledictionary dictionary]; } return self;} -(void) buildvehiclechassis {[NSException raise:nsinternalinconsistencyexception format:@ "Sorry, you cannot call directly ' %@%d ' method '%@ ', you need to overload the method in subclasses by inheriting its subclasses, [NSString stringwithutf8string:__file__].lastpathcomponent, __line__, Nsstrin Gfromselector (_cmd)];} -(void) Buildvehicleengine {[NSException raise:nsinternalinconsistencyexception format:@ "Sorry, you cannot directly call '% Method '%@ ' in @%d ', you need to overload the method in subclasses by inheriting its subclasses, [NSString stringwithutf8string:__file__].lastpathcomponent, __line__, NSString Fromselector (_cmd)];} -(void) buildvehiclewheels {[NSException raise:nsinternalinconsistencyexception format:@ "Sorry, you cannot call directly '%@%d ' method '%@ ', you need to overload the method in subclasses by inheriting its subclasses, [NSString stringwithutf8string:__file__].lastpathcomponent, __line__, Nsstrin Gfromselector (_cmd)];} -(void) buildvehicledoors {[NSException raise:nsinternalinconsistencyexception format:@ "Sorry, you cannot call '%@ ' directly %d ' method '%@ ', you need to overload the method in subclasses by inheriting its subclasses, [NSString stringwithutf8string:__file__].lastpathcomponent, __line__, NSSTRINGF Romselector (_cmd)];} @end
vehiclebuilderprotocol.h// builderpattern//// Created by youxianming on 15/8/18.// Copyright ( c) 2015 youxianming. All rights reserved.//#import <Foundation/Foundation.h> @protocol vehiclebuilderprotocol <nsobject>@ required/** * Manufacturing automotive chassis */-(void) buildvehiclechassis;/** * manufacturing automotive engine */-(void) buildvehicleengine;/** * Manufacturing Automotive Wheels */-(void) buildvehiclewheels;/** * manufacture car door */-(void) buildvehicledoors; @end
vehicleassemblyplant.h// builderpattern//// Created by youxianming on 15/8/18.// Copyright (c) 2015 youxianming. All rights reserved.//#import <Foundation/Foundation.h> #import "VehicleBuilder.h"/** * Vehicle Assembly Plant */@interface vehicleassemblyplant:nsobject/** * Assembly Vehicle * * @param vehiclebuilder Assembly Plan * * @return assembled vehicle */+ (Vehiclebuilde R *) vehicleassembly: (Vehiclebuilder *) Vehiclebuilder; @end
vehicleassemblyplant.m// builderpattern//// Created by youxianming on 15/8/18.// Copyright (c) 2015 youxianming. All rights reserved.//#import "VehicleAssemblyPlant.h" @implementation vehicleassemblyplant+ (Vehiclebuilder *) vehicleassembly: (Vehiclebuilder *) vehiclebuilder { [vehiclebuilder buildvehiclechassis]; [Vehiclebuilder buildvehicledoors]; [Vehiclebuilder Buildvehicleengine]; [Vehiclebuilder Buildvehiclewheels]; return vehiclebuilder;} @end
Details
iOS design mode-builder