iOS design mode-builder

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.