diff --git "a/19\350\201\214\350\264\243\351\223\276\346\250\241\345\274\217/19\350\201\214\350\264\243\351\223\276\346\250\241\345\274\217/HCDMnager.m" "b/19\350\201\214\350\264\243\351\223\276\346\250\241\345\274\217/19\350\201\214\350\264\243\351\223\276\346\250\241\345\274\217/HCDMnager.m" index 78bfe8b..35c05e5 100644 --- "a/19\350\201\214\350\264\243\351\223\276\346\250\241\345\274\217/19\350\201\214\350\264\243\351\223\276\346\250\241\345\274\217/HCDMnager.m" +++ "b/19\350\201\214\350\264\243\351\223\276\346\250\241\345\274\217/19\350\201\214\350\264\243\351\223\276\346\250\241\345\274\217/HCDMnager.m" @@ -10,6 +10,10 @@ #import "HCDReuquest.h" @implementation HCDMnager -(instancetype)initWithName:(NSString *)name{ + if ([self isMemberOfClass:[HCDMnager class]]) { + NSAssert(NO, @"基类不能被直接初始化。"); + } + self = [super init]; if (self) { _name = name; diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" index e9e5e38..29e629e 100644 --- "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 007B61981EE8E5D900AE878A /* HCDPerson.m in Sources */ = {isa = PBXBuildFile; fileRef = 007B61971EE8E5D900AE878A /* HCDPerson.m */; }; + 007B619B1EE8EA5400AE878A /* HCDPresonBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 007B619A1EE8EA5400AE878A /* HCDPresonBuilder.m */; }; 4DC94D991ECC6A8500A8DB96 /* HCDHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94D981ECC6A8500A8DB96 /* HCDHeader.m */; }; 4DC94D9C1ECC6A9700A8DB96 /* HCDBody.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94D9B1ECC6A9700A8DB96 /* HCDBody.m */; }; 4DC94D9F1ECC6AA600A8DB96 /* HCDLeg.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94D9E1ECC6AA600A8DB96 /* HCDLeg.m */; }; @@ -34,6 +36,10 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 007B61961EE8E5D900AE878A /* HCDPerson.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDPerson.h; sourceTree = ""; }; + 007B61971EE8E5D900AE878A /* HCDPerson.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDPerson.m; sourceTree = ""; }; + 007B61991EE8EA5400AE878A /* HCDPresonBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDPresonBuilder.h; sourceTree = ""; }; + 007B619A1EE8EA5400AE878A /* HCDPresonBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDPresonBuilder.m; sourceTree = ""; }; 4DC94D971ECC6A8500A8DB96 /* HCDHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDHeader.h; sourceTree = ""; }; 4DC94D981ECC6A8500A8DB96 /* HCDHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDHeader.m; sourceTree = ""; }; 4DC94D9A1ECC6A9700A8DB96 /* HCDBody.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDBody.h; sourceTree = ""; }; @@ -82,6 +88,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 007B61951EE8E5B800AE878A /* 产品 */ = { + isa = PBXGroup; + children = ( + 007B61961EE8E5D900AE878A /* HCDPerson.h */, + 007B61971EE8E5D900AE878A /* HCDPerson.m */, + ); + name = "产品"; + sourceTree = ""; + }; 4DC94D961ECC6A5E00A8DB96 /* 工具类 */ = { isa = PBXGroup; children = ( @@ -109,6 +124,8 @@ 4DC94DA41ECC6D2600A8DB96 /* Builder */ = { isa = PBXGroup; children = ( + 007B61991EE8EA5400AE878A /* HCDPresonBuilder.h */, + 007B619A1EE8EA5400AE878A /* HCDPresonBuilder.m */, DD4F86DB1B7C48ED00A32343 /* HCDPresionBuilder.h */, DD4F86DC1B7C497400A32343 /* HCDPersonThinBuilder.h */, DD4F86DD1B7C497400A32343 /* HCDPersonThinBuilder.m */, @@ -181,6 +198,7 @@ DD4F86DA1B7C48C000A32343 /* 建造者模式 */ = { isa = PBXGroup; children = ( + 007B61951EE8E5B800AE878A /* 产品 */, 4DC94DA41ECC6D2600A8DB96 /* Builder */, 4DC94DA31ECC6D1E00A8DB96 /* Director */, 4DC94D961ECC6A5E00A8DB96 /* 工具类 */, @@ -293,6 +311,8 @@ 4DC94DA21ECC6ACA00A8DB96 /* HCDArm.m in Sources */, 4DC94D9C1ECC6A9700A8DB96 /* HCDBody.m in Sources */, 4DC94D991ECC6A8500A8DB96 /* HCDHeader.m in Sources */, + 007B61981EE8E5D900AE878A /* HCDPerson.m in Sources */, + 007B619B1EE8EA5400AE878A /* HCDPresonBuilder.m in Sources */, DD4F86BD1B7C38C600A32343 /* ViewController.m in Sources */, DD4F86DE1B7C497400A32343 /* HCDPersonThinBuilder.m in Sources */, DD4F86BA1B7C38C600A32343 /* AppDelegate.m in Sources */, diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPerson.h" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPerson.h" new file mode 100644 index 0000000..9a90b93 --- /dev/null +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPerson.h" @@ -0,0 +1,21 @@ +// +// HCDPerson.h +// 8建造者模式 +// +// Created by Robin on 08/06/2017. +// Copyright © 2017 黄成都. All rights reserved. +// + +#import + +@interface HCDPerson : NSObject + +@property (nonatomic, copy) NSString * header; +@property (nonatomic, copy) NSString * body; +@property (nonatomic, copy) NSString * leftArm; +@property (nonatomic, copy) NSString * rightArm; +@property (nonatomic, copy) NSString * leftLeg; +@property (nonatomic, copy) NSString * rightLeg; + +- (void)printInfo; +@end diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPerson.m" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPerson.m" new file mode 100644 index 0000000..e6116a7 --- /dev/null +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPerson.m" @@ -0,0 +1,30 @@ +// +// HCDPerson.m +// 8建造者模式 +// +// Created by Robin on 08/06/2017. +// Copyright © 2017 黄成都. All rights reserved. +// + +#import "HCDPerson.h" +#import + +@implementation HCDPerson + +- (void)printInfo { + + NSString * description = @""; + unsigned int count; + Ivar * list = class_copyIvarList([self class], &count); + for (unsigned int i = 0; i < count; i++) { + Ivar ivar = list[i]; + NSString * name = @(ivar_getName(ivar)); + id value = object_getIvar(self, ivar); + NSString * subInfo = [NSString stringWithFormat:@"%@:%@ ",name,value]; + description = [description stringByAppendingString:subInfo]; + } + + NSLog(@"%@",description); +} + +@end diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonBuilderDirector.h" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonBuilderDirector.h" index 8c251d8..791d0d2 100644 --- "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonBuilderDirector.h" +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonBuilderDirector.h" @@ -7,13 +7,12 @@ // #import -#import "HCDPresionBuilder.h" - -@interface HCDPersonBuilderDirector : NSObject +#import "HCDPresonBuilder.h" +@class HCDPerson; -@property(nonatomic, strong)HCDPresionBuilder builder; +@interface HCDPersonBuilderDirector : NSObject --(void)buildPerson; +- (HCDPerson *)buildPerson:(HCDPresonBuilder *)builder; @end diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonBuilderDirector.m" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonBuilderDirector.m" index d47aa64..310f3e4 100644 --- "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonBuilderDirector.m" +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonBuilderDirector.m" @@ -9,7 +9,7 @@ #import "HCDPersonBuilderDirector.h" #import "HCDPersonFatBuilder.h" #import "HCDPersonThinBuilder.h" - +#import "HCDPerson.h" @interface HCDPersonBuilderDirector () @@ -18,9 +18,18 @@ @interface HCDPersonBuilderDirector () @implementation HCDPersonBuilderDirector --(void)buildPerson{ - NSLog(@"===============director指挥builder开始建造===================="); - [self.builder buildPerson]; +- (HCDPerson *)buildPerson:(HCDPresonBuilder *)builder { + + NSLog(@"===============director指挥建造过程===================="); + + [builder buildHead]; + [builder buildBody]; + [builder buildArmLeft]; + [builder buildArmRight]; + [builder buildLegLeft]; + [builder buildLegRight]; + + return [builder buildPerson]; } @end diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonFatBuilder.h" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonFatBuilder.h" index 03c5717..d902331 100644 --- "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonFatBuilder.h" +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonFatBuilder.h" @@ -7,8 +7,8 @@ // #import -#import "HCDPresionBuilder.h" +#import "HCDPresonBuilder.h" -@interface HCDPersonFatBuilder : NSObject +@interface HCDPersonFatBuilder : HCDPresonBuilder @end diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonFatBuilder.m" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonFatBuilder.m" index dc8d3d4..4702388 100644 --- "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonFatBuilder.m" +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonFatBuilder.m" @@ -32,42 +32,39 @@ -(instancetype)init{ return self; } --(void)buildPerson{ - [self buildHead]; - [self buildBody]; - [self buildArmLeft]; - [self buildArmRight]; - [self buildLegLeft]; - [self buildLegRight]; -} - - (void)buildHead { NSLog(@"建造胖子的头部"); [self.header work]; + self->person.header = @"胖子的头部"; } - (void)buildBody { NSLog(@"建造胖子的身体"); [self.body work]; + self->person.body = @"胖子的身体"; } - (void)buildArmLeft { NSLog(@"建造胖子的左手"); [self.arm work]; + self->person.leftArm = @"胖子的左手"; } - (void)buildArmRight { NSLog(@"建造胖子的右手"); [self.arm work]; + self->person.rightArm = @"胖子的右手"; } - (void)buildLegLeft { NSLog(@"建造胖子的左脚"); [self.leg work]; + self->person.leftLeg = @"胖子的左脚"; } - (void)buildLegRight { NSLog(@"建造胖子的右脚"); [self.leg work]; + self->person.rightLeg = @"胖子的右脚"; } @end diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonThinBuilder.h" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonThinBuilder.h" index aea38f2..2163b99 100644 --- "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonThinBuilder.h" +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonThinBuilder.h" @@ -7,8 +7,8 @@ // #import -#import "HCDPresionBuilder.h" +#import "HCDPresonBuilder.h" -@interface HCDPersonThinBuilder : NSObject +@interface HCDPersonThinBuilder : HCDPresonBuilder @end diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonThinBuilder.m" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonThinBuilder.m" index ada8e39..929b4db 100644 --- "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonThinBuilder.m" +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPersonThinBuilder.m" @@ -34,43 +34,40 @@ -(instancetype)init{ return self; } --(void)buildPerson{ - [self buildHead]; - [self buildBody]; - [self buildArmLeft]; - [self buildArmRight]; - [self buildLegLeft]; - [self buildLegRight]; -} - - (void)buildHead { NSLog(@"建造瘦子的头部"); [self.header work]; + self->person.header = @"瘦子的头部"; } - (void)buildBody { NSLog(@"建造瘦子的身体"); - [self.body work]; + [self.body work]; + self->person.body = @"瘦子的身体"; } - (void)buildArmLeft { NSLog(@"建造瘦子的左手"); [self.arm work]; + self->person.leftArm = @"瘦子的左手"; } - (void)buildArmRight { NSLog(@"建造瘦子的右手"); [self.arm work]; + self->person.rightArm = @"瘦子的右手"; } - (void)buildLegLeft { NSLog(@"建造瘦子的左脚"); [self.leg work]; + self->person.leftLeg = @"瘦子的左脚"; } - (void)buildLegRight { NSLog(@"建造瘦子的右脚"); [self.leg work]; + self->person.rightLeg = @"瘦子的右脚"; } diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPresionBuilder.h" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPresionBuilder.h" deleted file mode 100644 index 03c4587..0000000 --- "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPresionBuilder.h" +++ /dev/null @@ -1,31 +0,0 @@ -// -// HCDPresionBuilder.h -// 8建造者模式 -// -// Created by yifan on 15/8/13. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import - -typedef NS_ENUM(NSUInteger,BuildOption){ - BuildFat, - BuildThin -}; - - - -@protocol HCDPresionBuilder - --(void)buildHead; --(void)buildBody; --(void)buildArmLeft; --(void)buildArmRight; --(void)buildLegLeft; --(void)buildLegRight; - -- (void)buildPerson; - -@end - -typedef id HCDPresionBuilder; diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPresonBuilder.h" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPresonBuilder.h" new file mode 100644 index 0000000..a030ed0 --- /dev/null +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPresonBuilder.h" @@ -0,0 +1,25 @@ +// +// HCDPresonBuilder.h +// 8建造者模式 +// +// Created by Robin on 08/06/2017. +// Copyright © 2017 黄成都. All rights reserved. +// + +#import +#import "HCDPerson.h" + +@interface HCDPresonBuilder : NSObject { + HCDPerson * person; +} + +- (void)buildHead; +- (void)buildBody; +- (void)buildArmLeft; +- (void)buildArmRight; +- (void)buildLegLeft; +- (void)buildLegRight; + +- (HCDPerson *)buildPerson; + +@end diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPresonBuilder.m" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPresonBuilder.m" new file mode 100644 index 0000000..0ea9db5 --- /dev/null +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/HCDPresonBuilder.m" @@ -0,0 +1,57 @@ +// +// HCDPresonBuilder.m +// 8建造者模式 +// +// Created by Robin on 08/06/2017. +// Copyright © 2017 黄成都. All rights reserved. +// + +#import "HCDPresonBuilder.h" +#import + +#define MethodNotImplemented() @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"You must override method %@ in subclass %s",NSStringFromSelector(_cmd),class_getName(object_getClass(self))] userInfo:nil] + +@implementation HCDPresonBuilder + +- (instancetype)init{ + if ([self isMemberOfClass:[HCDPresonBuilder class]]) { + NSAssert(NO, @"Abstract class can't be inited directly."); + } + + self = [super init]; + if (self) { + person = [[HCDPerson alloc]init]; + } + + return self; +} + +- (void)buildHead { + MethodNotImplemented(); +} + +- (void)buildBody { + MethodNotImplemented(); +} + +- (void)buildArmLeft { + MethodNotImplemented(); +} + +- (void)buildArmRight { + MethodNotImplemented(); +} + +- (void)buildLegLeft { + MethodNotImplemented(); +} + +- (void)buildLegRight { + MethodNotImplemented(); +} + +- (HCDPerson *)buildPerson { + return person; +} + +@end diff --git "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/ViewController.m" "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/ViewController.m" index c44cd22..04f8f5f 100644 --- "a/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/ViewController.m" +++ "b/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/8\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217/ViewController.m" @@ -10,7 +10,7 @@ #import "HCDPersonBuilderDirector.h" #import "HCDPersonFatBuilder.h" #import "HCDPersonThinBuilder.h" - +#import "HCDPerson.h" @interface ViewController () @@ -25,21 +25,19 @@ - (void)viewDidLoad { - (IBAction)buildFat:(id)sender { HCDPersonBuilderDirector *director = [[HCDPersonBuilderDirector alloc]init]; - HCDPresionBuilder builder = [[HCDPersonFatBuilder alloc]init]; - //为director指定builder - director.builder = builder; - //director发出构建的指令,builder负责具体的建造过程 - [director buildPerson]; + HCDPresonBuilder * builder = [[HCDPersonFatBuilder alloc]init]; + //director负责建造过程,builder负责具体的构建 + HCDPerson * person = [director buildPerson:builder]; + [person printInfo]; } - (IBAction)buildThin:(id)sender { HCDPersonBuilderDirector *director = [[HCDPersonBuilderDirector alloc]init]; - HCDPresionBuilder builder = [[HCDPersonThinBuilder alloc]init]; - //为director指定builder - director.builder = builder; - //director发出构建的指令,builder负责具体的建造过程 - [director buildPerson]; + HCDPresonBuilder * builder = [[HCDPersonThinBuilder alloc]init]; + //director负责建造过程,builder负责具体的构建 + HCDPerson * person = [director buildPerson:builder]; + [person printInfo]; } @end