Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 19职责链模式/19职责链模式/HCDMnager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions 8建造者模式/8建造者模式.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
007B61971EE8E5D900AE878A /* HCDPerson.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDPerson.m; sourceTree = "<group>"; };
007B61991EE8EA5400AE878A /* HCDPresonBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDPresonBuilder.h; sourceTree = "<group>"; };
007B619A1EE8EA5400AE878A /* HCDPresonBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDPresonBuilder.m; sourceTree = "<group>"; };
4DC94D971ECC6A8500A8DB96 /* HCDHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDHeader.h; sourceTree = "<group>"; };
4DC94D981ECC6A8500A8DB96 /* HCDHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDHeader.m; sourceTree = "<group>"; };
4DC94D9A1ECC6A9700A8DB96 /* HCDBody.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDBody.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -82,6 +88,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
007B61951EE8E5B800AE878A /* 产品 */ = {
isa = PBXGroup;
children = (
007B61961EE8E5D900AE878A /* HCDPerson.h */,
007B61971EE8E5D900AE878A /* HCDPerson.m */,
);
name = "产品";
sourceTree = "<group>";
};
4DC94D961ECC6A5E00A8DB96 /* 工具类 */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -109,6 +124,8 @@
4DC94DA41ECC6D2600A8DB96 /* Builder */ = {
isa = PBXGroup;
children = (
007B61991EE8EA5400AE878A /* HCDPresonBuilder.h */,
007B619A1EE8EA5400AE878A /* HCDPresonBuilder.m */,
DD4F86DB1B7C48ED00A32343 /* HCDPresionBuilder.h */,
DD4F86DC1B7C497400A32343 /* HCDPersonThinBuilder.h */,
DD4F86DD1B7C497400A32343 /* HCDPersonThinBuilder.m */,
Expand Down Expand Up @@ -181,6 +198,7 @@
DD4F86DA1B7C48C000A32343 /* 建造者模式 */ = {
isa = PBXGroup;
children = (
007B61951EE8E5B800AE878A /* 产品 */,
4DC94DA41ECC6D2600A8DB96 /* Builder */,
4DC94DA31ECC6D1E00A8DB96 /* Director */,
4DC94D961ECC6A5E00A8DB96 /* 工具类 */,
Expand Down Expand Up @@ -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 */,
Expand Down
21 changes: 21 additions & 0 deletions 8建造者模式/8建造者模式/HCDPerson.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// HCDPerson.h
// 8建造者模式
//
// Created by Robin on 08/06/2017.
// Copyright © 2017 黄成都. All rights reserved.
//

#import <Foundation/Foundation.h>

@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
30 changes: 30 additions & 0 deletions 8建造者模式/8建造者模式/HCDPerson.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// HCDPerson.m
// 8建造者模式
//
// Created by Robin on 08/06/2017.
// Copyright © 2017 黄成都. All rights reserved.
//

#import "HCDPerson.h"
#import <objc/runtime.h>

@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
9 changes: 4 additions & 5 deletions 8建造者模式/8建造者模式/HCDPersonBuilderDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
//

#import <Foundation/Foundation.h>
#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
17 changes: 13 additions & 4 deletions 8建造者模式/8建造者模式/HCDPersonBuilderDirector.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "HCDPersonBuilderDirector.h"
#import "HCDPersonFatBuilder.h"
#import "HCDPersonThinBuilder.h"

#import "HCDPerson.h"

@interface HCDPersonBuilderDirector ()

Expand All @@ -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
4 changes: 2 additions & 2 deletions 8建造者模式/8建造者模式/HCDPersonFatBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

#import <Foundation/Foundation.h>
#import "HCDPresionBuilder.h"
#import "HCDPresonBuilder.h"

@interface HCDPersonFatBuilder : NSObject<HCDPresionBuilder>
@interface HCDPersonFatBuilder : HCDPresonBuilder

@end
15 changes: 6 additions & 9 deletions 8建造者模式/8建造者模式/HCDPersonFatBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions 8建造者模式/8建造者模式/HCDPersonThinBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

#import <Foundation/Foundation.h>
#import "HCDPresionBuilder.h"
#import "HCDPresonBuilder.h"

@interface HCDPersonThinBuilder : NSObject<HCDPresionBuilder>
@interface HCDPersonThinBuilder : HCDPresonBuilder

@end
17 changes: 7 additions & 10 deletions 8建造者模式/8建造者模式/HCDPersonThinBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @"瘦子的右脚";
}


Expand Down
31 changes: 0 additions & 31 deletions 8建造者模式/8建造者模式/HCDPresionBuilder.h

This file was deleted.

25 changes: 25 additions & 0 deletions 8建造者模式/8建造者模式/HCDPresonBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// HCDPresonBuilder.h
// 8建造者模式
//
// Created by Robin on 08/06/2017.
// Copyright © 2017 黄成都. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "HCDPerson.h"

@interface HCDPresonBuilder : NSObject {
HCDPerson * person;
}

- (void)buildHead;
- (void)buildBody;
- (void)buildArmLeft;
- (void)buildArmRight;
- (void)buildLegLeft;
- (void)buildLegRight;

- (HCDPerson *)buildPerson;

@end
Loading