iOS design mode-builder

Source: Internet
Author: User

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

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.