diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217.xcodeproj/project.pbxproj" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217.xcodeproj/project.pbxproj" index 70c24f1..8fd3849 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217.xcodeproj/project.pbxproj" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217.xcodeproj/project.pbxproj" @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 4DC94DA91ECD259500A8DB96 /* HCDWorkSoftWare.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94DA81ECD259500A8DB96 /* HCDWorkSoftWare.m */; }; + 4DC94DAC1ECD25B800A8DB96 /* HCDPlaySoftWare.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94DAB1ECD25B800A8DB96 /* HCDPlaySoftWare.m */; }; DD2D689C1B7ED92400F9E848 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D689B1B7ED92400F9E848 /* main.m */; }; DD2D689F1B7ED92400F9E848 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D689E1B7ED92400F9E848 /* AppDelegate.m */; }; DD2D68A21B7ED92400F9E848 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68A11B7ED92400F9E848 /* ViewController.m */; }; @@ -17,10 +19,7 @@ DD2D68C41B7F008B00F9E848 /* 桥接模式.png in Resources */ = {isa = PBXBuildFile; fileRef = DD2D68C31B7F008B00F9E848 /* 桥接模式.png */; }; DD2D68C81B7F025700F9E848 /* HCDPhone.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68C71B7F025700F9E848 /* HCDPhone.m */; }; DD2D68CB1B7F026C00F9E848 /* HCDNokiaPhone.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68CA1B7F026C00F9E848 /* HCDNokiaPhone.m */; }; - DD2D68CE1B7F02B200F9E848 /* HCDSonyPhone.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68CD1B7F02B200F9E848 /* HCDSonyPhone.m */; }; DD2D68D21B7F02F300F9E848 /* HCDGameSoftware.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68D11B7F02F300F9E848 /* HCDGameSoftware.m */; }; - DD2D68D51B7F030700F9E848 /* HCDAddressListSofeware.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68D41B7F030700F9E848 /* HCDAddressListSofeware.m */; }; - DD2D68D81B7F057400F9E848 /* HCDGameNokiaSoftware.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68D71B7F057400F9E848 /* HCDGameNokiaSoftware.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -34,6 +33,10 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 4DC94DA71ECD259500A8DB96 /* HCDWorkSoftWare.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDWorkSoftWare.h; sourceTree = ""; }; + 4DC94DA81ECD259500A8DB96 /* HCDWorkSoftWare.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDWorkSoftWare.m; sourceTree = ""; }; + 4DC94DAA1ECD25B800A8DB96 /* HCDPlaySoftWare.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDPlaySoftWare.h; sourceTree = ""; }; + 4DC94DAB1ECD25B800A8DB96 /* HCDPlaySoftWare.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDPlaySoftWare.m; sourceTree = ""; }; DD2D68961B7ED92400F9E848 /* 17桥接模式.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "17桥接模式.app"; sourceTree = BUILT_PRODUCTS_DIR; }; DD2D689A1B7ED92400F9E848 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DD2D689B1B7ED92400F9E848 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -52,15 +55,9 @@ DD2D68C71B7F025700F9E848 /* HCDPhone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDPhone.m; sourceTree = ""; }; DD2D68C91B7F026C00F9E848 /* HCDNokiaPhone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDNokiaPhone.h; sourceTree = ""; }; DD2D68CA1B7F026C00F9E848 /* HCDNokiaPhone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDNokiaPhone.m; sourceTree = ""; }; - DD2D68CC1B7F02B200F9E848 /* HCDSonyPhone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDSonyPhone.h; sourceTree = ""; }; - DD2D68CD1B7F02B200F9E848 /* HCDSonyPhone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDSonyPhone.m; sourceTree = ""; }; DD2D68CF1B7F02D700F9E848 /* HCDSoftware.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDSoftware.h; sourceTree = ""; }; DD2D68D01B7F02F300F9E848 /* HCDGameSoftware.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDGameSoftware.h; sourceTree = ""; }; DD2D68D11B7F02F300F9E848 /* HCDGameSoftware.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDGameSoftware.m; sourceTree = ""; }; - DD2D68D31B7F030700F9E848 /* HCDAddressListSofeware.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDAddressListSofeware.h; sourceTree = ""; }; - DD2D68D41B7F030700F9E848 /* HCDAddressListSofeware.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDAddressListSofeware.m; sourceTree = ""; }; - DD2D68D61B7F057400F9E848 /* HCDGameNokiaSoftware.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDGameNokiaSoftware.h; sourceTree = ""; }; - DD2D68D71B7F057400F9E848 /* HCDGameNokiaSoftware.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDGameNokiaSoftware.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -81,6 +78,31 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4DC94DA51ECD23A600A8DB96 /* Abstraction */ = { + isa = PBXGroup; + children = ( + DD2D68C61B7F025700F9E848 /* HCDPhone.h */, + DD2D68C71B7F025700F9E848 /* HCDPhone.m */, + DD2D68C91B7F026C00F9E848 /* HCDNokiaPhone.h */, + DD2D68CA1B7F026C00F9E848 /* HCDNokiaPhone.m */, + ); + name = Abstraction; + sourceTree = ""; + }; + 4DC94DA61ECD23B100A8DB96 /* Implementor */ = { + isa = PBXGroup; + children = ( + DD2D68CF1B7F02D700F9E848 /* HCDSoftware.h */, + DD2D68D01B7F02F300F9E848 /* HCDGameSoftware.h */, + DD2D68D11B7F02F300F9E848 /* HCDGameSoftware.m */, + 4DC94DA71ECD259500A8DB96 /* HCDWorkSoftWare.h */, + 4DC94DA81ECD259500A8DB96 /* HCDWorkSoftWare.m */, + 4DC94DAA1ECD25B800A8DB96 /* HCDPlaySoftWare.h */, + 4DC94DAB1ECD25B800A8DB96 /* HCDPlaySoftWare.m */, + ); + name = Implementor; + sourceTree = ""; + }; DD2D688D1B7ED92400F9E848 = { isa = PBXGroup; children = ( @@ -153,19 +175,8 @@ DD2D68C51B7F009000F9E848 /* 桥接模式 */ = { isa = PBXGroup; children = ( - DD2D68C61B7F025700F9E848 /* HCDPhone.h */, - DD2D68C71B7F025700F9E848 /* HCDPhone.m */, - DD2D68C91B7F026C00F9E848 /* HCDNokiaPhone.h */, - DD2D68CA1B7F026C00F9E848 /* HCDNokiaPhone.m */, - DD2D68CC1B7F02B200F9E848 /* HCDSonyPhone.h */, - DD2D68CD1B7F02B200F9E848 /* HCDSonyPhone.m */, - DD2D68CF1B7F02D700F9E848 /* HCDSoftware.h */, - DD2D68D01B7F02F300F9E848 /* HCDGameSoftware.h */, - DD2D68D11B7F02F300F9E848 /* HCDGameSoftware.m */, - DD2D68D31B7F030700F9E848 /* HCDAddressListSofeware.h */, - DD2D68D41B7F030700F9E848 /* HCDAddressListSofeware.m */, - DD2D68D61B7F057400F9E848 /* HCDGameNokiaSoftware.h */, - DD2D68D71B7F057400F9E848 /* HCDGameNokiaSoftware.m */, + 4DC94DA61ECD23B100A8DB96 /* Implementor */, + 4DC94DA51ECD23A600A8DB96 /* Abstraction */, ); name = "桥接模式"; sourceTree = ""; @@ -271,13 +282,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - DD2D68D51B7F030700F9E848 /* HCDAddressListSofeware.m in Sources */, + 4DC94DAC1ECD25B800A8DB96 /* HCDPlaySoftWare.m in Sources */, DD2D68A21B7ED92400F9E848 /* ViewController.m in Sources */, + 4DC94DA91ECD259500A8DB96 /* HCDWorkSoftWare.m in Sources */, DD2D689F1B7ED92400F9E848 /* AppDelegate.m in Sources */, DD2D68CB1B7F026C00F9E848 /* HCDNokiaPhone.m in Sources */, DD2D68D21B7F02F300F9E848 /* HCDGameSoftware.m in Sources */, - DD2D68D81B7F057400F9E848 /* HCDGameNokiaSoftware.m in Sources */, - DD2D68CE1B7F02B200F9E848 /* HCDSonyPhone.m in Sources */, DD2D68C81B7F025700F9E848 /* HCDPhone.m in Sources */, DD2D689C1B7ED92400F9E848 /* main.m in Sources */, ); diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/Base.lproj/Main.storyboard" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/Base.lproj/Main.storyboard" index d912f9d..75e09b1 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/Base.lproj/Main.storyboard" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/Base.lproj/Main.storyboard" @@ -1,21 +1,52 @@ - + + + + - + + + - + - + - + + + + + + diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDAddressListSofeware.h" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDAddressListSofeware.h" deleted file mode 100644 index ec3ae45..0000000 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDAddressListSofeware.h" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDAddressListSofeware.h -// 17桥接模式 -// -// Created by yifan on 15/8/15. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import -#import "HCDSoftware.h" -@interface HCDAddressListSofeware : NSObject - -@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDAddressListSofeware.m" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDAddressListSofeware.m" deleted file mode 100644 index 1ab5652..0000000 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDAddressListSofeware.m" +++ /dev/null @@ -1,15 +0,0 @@ -// -// HCDAddressListSofeware.m -// 17桥接模式 -// -// Created by yifan on 15/8/15. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDAddressListSofeware.h" - -@implementation HCDAddressListSofeware --(void)run{ - NSLog(@"运行通讯录手机软件"); -} -@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameNokiaSoftware.h" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameNokiaSoftware.h" deleted file mode 100644 index 887a8e1..0000000 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameNokiaSoftware.h" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDGameNokiaSoftware.h -// 17桥接模式 -// -// Created by yifan on 15/8/15. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDGameSoftware.h" - -@interface HCDGameNokiaSoftware : HCDGameSoftware - -@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameNokiaSoftware.m" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameNokiaSoftware.m" deleted file mode 100644 index a7a9e34..0000000 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameNokiaSoftware.m" +++ /dev/null @@ -1,15 +0,0 @@ -// -// HCDGameNokiaSoftware.m -// 17桥接模式 -// -// Created by yifan on 15/8/15. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDGameNokiaSoftware.h" - -@implementation HCDGameNokiaSoftware --(void)run{ - NSLog(@"运行Nokia的游戏软件"); -} -@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameSoftware.h" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameSoftware.h" index 049d551..679371b 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameSoftware.h" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameSoftware.h" @@ -8,6 +8,8 @@ #import #import "HCDSoftware.h" + + @interface HCDGameSoftware : NSObject @end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameSoftware.m" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameSoftware.m" index da17642..fc62dc5 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameSoftware.m" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDGameSoftware.m" @@ -7,9 +7,19 @@ // #import "HCDGameSoftware.h" +#import "HCDSoftware.h" + +@interface HCDGameSoftware () + +@end @implementation HCDGameSoftware --(void)run{ - NSLog(@"运行游戏手机软件"); + +-(void)runQQDizhu{ + NSLog(@"GameSoftware开始QQ斗地主"); +} + +-(void)runQQMajiang{ + NSLog(@"GameSoftware开始QQ麻将"); } @end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDNokiaPhone.h" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDNokiaPhone.h" index b3346db..468d343 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDNokiaPhone.h" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDNokiaPhone.h" @@ -7,6 +7,7 @@ // #import "HCDPhone.h" + @interface HCDNokiaPhone : HCDPhone @end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDNokiaPhone.m" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDNokiaPhone.m" index b4274b9..e2f98f9 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDNokiaPhone.m" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDNokiaPhone.m" @@ -7,7 +7,45 @@ // #import "HCDNokiaPhone.h" +#import "HCDGameSoftware.h" +#import "HCDWorkSoftWare.h" +#import "HCDPlaySoftWare.h" + + +@interface HCDNokiaPhone () + +@end @implementation HCDNokiaPhone +@synthesize gameSoft = _gameSoft; +@synthesize workSoft = _workSoft; +@synthesize playSoft =_playSoft; + + +-(instancetype)init{ + self = [super init]; + if (self) { + _gameSoft = [[HCDGameSoftware alloc]init]; + _workSoft = [[HCDWorkSoftWare alloc]init]; + _playSoft = [[HCDPlaySoftWare alloc]init]; + } + return self; +} + + +-(void)work{ + [self.workSoft runXcode]; + [self.workSoft runWord]; +} + +-(void)play{ + [self.playSoft runWeixin]; + [self.playSoft runQQ]; +} + +-(void)game{ + [self.gameSoft runQQDizhu]; + [self.gameSoft runQQMajiang]; +} @end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPhone.h" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPhone.h" index 63f633b..6aab02f 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPhone.h" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPhone.h" @@ -8,7 +8,18 @@ #import #import "HCDSoftware.h" + +@class HCDGameSoftware; +@class HCDPlaySoftWare; +@class HCDWorkSoftWare; + @interface HCDPhone : NSObject -@property(nonatomic,strong)id softWare; --(void)playSoftPhone; + +@property(nonatomic, strong, readonly)HCDGameSoftware *gameSoft; +@property(nonatomic, strong, readonly)HCDWorkSoftWare *workSoft; +@property(nonatomic, strong, readonly)HCDPlaySoftWare *playSoft; + +-(void)work; +-(void)play; +-(void)game; @end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPhone.m" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPhone.m" index ada80ce..65b5570 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPhone.m" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPhone.m" @@ -9,7 +9,5 @@ #import "HCDPhone.h" @implementation HCDPhone --(void)playSoftPhone{ - [self.softWare run]; -} + @end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPlaySoftWare.h" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPlaySoftWare.h" new file mode 100644 index 0000000..0cad2ac --- /dev/null +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPlaySoftWare.h" @@ -0,0 +1,14 @@ +// +// HCDPlaySoftWare.h +// 17桥接模式 +// +// Created by huangchengdu on 17/5/18. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import +#import "HCDSoftware.h" + +@interface HCDPlaySoftWare : NSObject + +@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPlaySoftWare.m" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPlaySoftWare.m" new file mode 100644 index 0000000..87de6d9 --- /dev/null +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDPlaySoftWare.m" @@ -0,0 +1,26 @@ +// +// HCDPlaySoftWare.m +// 17桥接模式 +// +// Created by huangchengdu on 17/5/18. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "HCDPlaySoftWare.h" +#import "HCDSoftware.h" + +@interface HCDPlaySoftWare () + +@end + +@implementation HCDPlaySoftWare + +-(void)runQQ{ + NSLog(@"PlaySoftWare开始打开QQ"); +} + +-(void)runWeixin{ + NSLog(@"PlaySoftWare开始打开微信"); +} + +@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSoftware.h" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSoftware.h" index 6d9f7c6..10b55de 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSoftware.h" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSoftware.h" @@ -9,5 +9,12 @@ #import @protocol HCDSoftware --(void)run; +-(void)runQQ; +-(void)runWeixin; +-(void)runWord; +-(void)runXcode; +-(void)runQQDizhu; +-(void)runQQMajiang; @end + +typedef id HCDSoftware; diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSonyPhone.h" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSonyPhone.h" deleted file mode 100644 index 12cad31..0000000 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSonyPhone.h" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDSonyPhone.h -// 17桥接模式 -// -// Created by yifan on 15/8/15. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDPhone.h" - -@interface HCDSonyPhone : HCDPhone - -@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSonyPhone.m" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSonyPhone.m" deleted file mode 100644 index 8c517c8..0000000 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDSonyPhone.m" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDSonyPhone.m -// 17桥接模式 -// -// Created by yifan on 15/8/15. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDSonyPhone.h" - -@implementation HCDSonyPhone - -@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDWorkSoftWare.h" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDWorkSoftWare.h" new file mode 100644 index 0000000..5f01982 --- /dev/null +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDWorkSoftWare.h" @@ -0,0 +1,14 @@ +// +// HCDWorkSoftWare.h +// 17桥接模式 +// +// Created by huangchengdu on 17/5/18. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import +#import "HCDSoftware.h" + +@interface HCDWorkSoftWare : NSObject + +@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDWorkSoftWare.m" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDWorkSoftWare.m" new file mode 100644 index 0000000..e601bb9 --- /dev/null +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/HCDWorkSoftWare.m" @@ -0,0 +1,26 @@ +// +// HCDWorkSoftWare.m +// 17桥接模式 +// +// Created by huangchengdu on 17/5/18. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "HCDWorkSoftWare.h" +#import "HCDSoftware.h" + +@interface HCDWorkSoftWare () + +@end + +@implementation HCDWorkSoftWare + +-(void)runWord{ + NSLog(@"WorkSoftWare打开办公软件"); +} + +-(void)runXcode{ + NSLog(@"WorkSoftWare打开Xcode"); +} + +@end diff --git "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/ViewController.m" "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/ViewController.m" index 1e7f32b..b6655b1 100644 --- "a/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/ViewController.m" +++ "b/17\346\241\245\346\216\245\346\250\241\345\274\217/17\346\241\245\346\216\245\346\250\241\345\274\217/ViewController.m" @@ -9,28 +9,43 @@ #import "ViewController.h" #import "HCDPhone.h" #import "HCDNokiaPhone.h" -#import "HCDSonyPhone.h" -#import "HCDSoftware.h" -#import "HCDGameSoftware.h" -#import "HCDGameNokiaSoftware.h" -#import "HCDAddressListSofeware.h" -typedef id HCDSoftware; + + + + @interface ViewController () +@property(nonatomic, strong)HCDPhone *phone; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - HCDPhone *phone = [[HCDNokiaPhone alloc]init]; - HCDSoftware software = [[HCDGameNokiaSoftware alloc]init]; - [phone setSoftWare:software]; - [phone playSoftPhone]; - software = [[HCDAddressListSofeware alloc]init]; - [phone setSoftWare:software]; - [phone playSoftPhone]; + self.phone = [[HCDNokiaPhone alloc]init]; + + + +} + + +- (IBAction)play:(id)sender { + + [self.phone play]; + NSLog(@"============================"); +} + +- (IBAction)work:(id)sender { + + [self.phone work]; + NSLog(@"============================"); + +} + +- (IBAction)game:(id)sender { + [self.phone game]; + NSLog(@"============================"); } - (void)didReceiveMemoryWarning { diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/project.pbxproj" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/project.pbxproj" index 403ddbb..6731944 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/project.pbxproj" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/project.pbxproj" @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 4D18692E1EDFF75C00F8C3C0 /* HCDDuckOrder.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D18692D1EDFF75C00F8C3C0 /* HCDDuckOrder.m */; }; DD2D68E81B7F0E5500F9E848 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68E71B7F0E5500F9E848 /* main.m */; }; DD2D68EB1B7F0E5500F9E848 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68EA1B7F0E5500F9E848 /* AppDelegate.m */; }; DD2D68EE1B7F0E5500F9E848 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D68ED1B7F0E5500F9E848 /* ViewController.m */; }; @@ -33,6 +34,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 4D18692C1EDFF75C00F8C3C0 /* HCDDuckOrder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDDuckOrder.h; sourceTree = ""; }; + 4D18692D1EDFF75C00F8C3C0 /* HCDDuckOrder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDDuckOrder.m; sourceTree = ""; }; DD2D68E21B7F0E5500F9E848 /* 18命令模式.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "18命令模式.app"; sourceTree = BUILT_PRODUCTS_DIR; }; DD2D68E61B7F0E5500F9E848 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DD2D68E71B7F0E5500F9E848 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -147,6 +150,8 @@ DD2D69101B7F111000F9E848 /* HCDMuttonOrder.m */, DD2D69121B7F112600F9E848 /* HCDChickenOrder.h */, DD2D69131B7F112600F9E848 /* HCDChickenOrder.m */, + 4D18692C1EDFF75C00F8C3C0 /* HCDDuckOrder.h */, + 4D18692D1EDFF75C00F8C3C0 /* HCDDuckOrder.m */, DD2D69151B7F118100F9E848 /* HCDWorker.h */, DD2D69161B7F118100F9E848 /* HCDWorker.m */, DD2D69181B7F131E00F9E848 /* HCDWaiter.h */, @@ -266,6 +271,7 @@ DD2D68EE1B7F0E5500F9E848 /* ViewController.m in Sources */, DD2D68EB1B7F0E5500F9E848 /* AppDelegate.m in Sources */, DD2D68E81B7F0E5500F9E848 /* main.m in Sources */, + 4D18692E1EDFF75C00F8C3C0 /* HCDDuckOrder.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -460,6 +466,7 @@ DD2D69071B7F0E5500F9E848 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; DD2D69081B7F0E5500F9E848 /* Build configuration list for PBXNativeTarget "18命令模式Tests" */ = { isa = XCConfigurationList; @@ -468,6 +475,7 @@ DD2D690A1B7F0E5500F9E848 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/18\345\221\275\344\273\244\346\250\241\345\274\217.xcscheme" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/18\345\221\275\344\273\244\346\250\241\345\274\217.xcscheme" new file mode 100644 index 0000000..9d3bc16 --- /dev/null +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/18\345\221\275\344\273\244\346\250\241\345\274\217.xcscheme" @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/xcschememanagement.plist" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/xcschememanagement.plist" new file mode 100644 index 0000000..e70ea23 --- /dev/null +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/xcschememanagement.plist" @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + 18命令模式.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + DD2D68E11B7F0E5500F9E848 + + primary + + + DD2D68FA1B7F0E5500F9E848 + + primary + + + + + diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDChickenOrder.m" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDChickenOrder.m" index bb46c0a..51ec252 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDChickenOrder.m" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDChickenOrder.m" @@ -9,7 +9,9 @@ #import "HCDChickenOrder.h" @implementation HCDChickenOrder + -(void)executeOrder{ + NSLog(@"烤鸡"); [[HCDWorker sharedWorker] doChickenWork:self.orderString]; } @end diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDCustomr.h" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDCustomr.h" index 6417aac..f0e94fe 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDCustomr.h" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDCustomr.h" @@ -7,7 +7,16 @@ // #import + @class HCDOrder,HCDMuttonOrder,HCDChickenOrder; + +typedef NS_ENUM(NSUInteger,orderType){ + orderTypeMutton, + orderTypeChicken, + orderTypeDuck +}; + @interface HCDCustomr : NSObject --(HCDOrder *)pushOrderWithString:(NSString *)string type:(BOOL)type; + +-(HCDOrder *)pushOrderWithString:(NSString *)string type:(orderType)type; @end diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDCustomr.m" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDCustomr.m" index f7961a2..2d49ae1 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDCustomr.m" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDCustomr.m" @@ -9,14 +9,24 @@ #import "HCDCustomr.h" #import "HCDMuttonOrder.h" #import "HCDChickenOrder.h" +#import "HCDDuckOrder.h" + + + @implementation HCDCustomr --(HCDOrder *)pushOrderWithString:(NSString *)string type:(BOOL)type{ +-(HCDOrder *)pushOrderWithString:(NSString *)string type:(orderType)type{ HCDOrder *order = nil; - if (type) { - order = [[HCDMuttonOrder alloc]initWithOrderString:string]; - }else{ - order = [[HCDChickenOrder alloc]initWithOrderString:string]; + switch (type) { + case orderTypeMutton: + order = [[HCDMuttonOrder alloc]initWithOrderString:string]; + break; + case orderTypeChicken: + order = [[HCDChickenOrder alloc]initWithOrderString:string]; + break; + case orderTypeDuck: + order = [[HCDDuckOrder alloc]initWithOrderString:string]; + break; } return order; } diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDDuckOrder.h" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDDuckOrder.h" new file mode 100644 index 0000000..b0f2fc2 --- /dev/null +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDDuckOrder.h" @@ -0,0 +1,13 @@ +// +// HCDDuckOrder.h +// 18命令模式 +// +// Created by huangchengdu on 17/6/1. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "HCDOrder.h" + +@interface HCDDuckOrder : HCDOrder + +@end diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDDuckOrder.m" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDDuckOrder.m" new file mode 100644 index 0000000..576f56c --- /dev/null +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDDuckOrder.m" @@ -0,0 +1,17 @@ +// +// HCDDuckOrder.m +// 18命令模式 +// +// Created by huangchengdu on 17/6/1. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "HCDDuckOrder.h" + +@implementation HCDDuckOrder + +-(void)executeOrder{ + NSLog(@"烤鸭"); + [[HCDWorker sharedWorker] doChickenWork:self.orderString]; +} +@end diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDMuttonOrder.m" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDMuttonOrder.m" index 40facb9..b4b83a1 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDMuttonOrder.m" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDMuttonOrder.m" @@ -9,7 +9,9 @@ #import "HCDMuttonOrder.h" @implementation HCDMuttonOrder + -(void)executeOrder{ + NSLog(@"烤羊"); [[HCDWorker sharedWorker] doMuttonWork:self.orderString]; } @end diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDOrder.h" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDOrder.h" index d867f0b..6003221 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDOrder.h" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDOrder.h" @@ -9,8 +9,12 @@ #import #import "HCDOrder.h" #import "HCDWorker.h" + @interface HCDOrder : NSObject + @property(nonatomic,copy)NSString *orderString; --(instancetype)initWithOrderString:(NSString *)orderString;; + +-(instancetype)initWithOrderString:(NSString *)orderString; +//执行命令 -(void)executeOrder; @end diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWaiter.h" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWaiter.h" index 59886e4..66b2d04 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWaiter.h" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWaiter.h" @@ -10,7 +10,9 @@ #import "HCDOrder.h" #import "HCDMuttonOrder.h" #import "HCDChickenOrder.h" + @interface HCDWaiter : NSObject + -(void)addOrder:(HCDOrder *)order; -(void)deleteOrder:(HCDOrder *)order; -(void)notifyOrder; diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWaiter.m" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWaiter.m" index 1591905..43bace1 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWaiter.m" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWaiter.m" @@ -9,10 +9,12 @@ #import "HCDWaiter.h" @interface HCDWaiter () +//用于存储命令列表 @property(nonatomic,strong)NSMutableArray *orderList; @end @implementation HCDWaiter + -(instancetype)init{ self = [super init]; if (self) { @@ -21,12 +23,18 @@ -(instancetype)init{ return self; } -(void)addOrder:(HCDOrder *)order{ + NSLog(@"添加Order"); [self.orderList addObject:order]; } -(void)deleteOrder:(HCDOrder *)order{ + NSLog(@"取消Order"); [self.orderList removeObject:order]; } +/* + 命令接收完毕,开始执行命令 + */ -(void)notifyOrder{ + NSLog(@"====开始执行Order==="); for (HCDOrder *order in self.orderList) { [order executeOrder]; } diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWorker.h" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWorker.h" index df166a9..ebfec70 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWorker.h" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWorker.h" @@ -9,8 +9,10 @@ #import @interface HCDWorker : NSObject + +(instancetype)sharedWorker; + -(void)doMuttonWork:(NSString *)work; -(void)doChickenWork:(NSString *)work; - +-(void)doDuckWork:(NSString *)work; @end diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWorker.m" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWorker.m" index 2080771..d775a03 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWorker.m" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/HCDWorker.m" @@ -9,6 +9,7 @@ #import "HCDWorker.h" @implementation HCDWorker + +(instancetype)sharedWorker{ static dispatch_once_t once; static HCDWorker *sharedWorker = nil; @@ -24,4 +25,9 @@ -(void)doMuttonWork:(NSString *)work{ -(void)doChickenWork:(NSString *)work{ NSLog(@"厨师考鸡肉:%@",work); } + +-(void)doDuckWork:(NSString *)work{ + NSLog(@"厨师烤鸭肉:%@",work); +} + @end diff --git "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/ViewController.m" "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/ViewController.m" index afce231..d7b4e5b 100644 --- "a/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/ViewController.m" +++ "b/18\345\221\275\344\273\244\346\250\241\345\274\217/18\345\221\275\344\273\244\346\250\241\345\274\217/ViewController.m" @@ -10,6 +10,8 @@ #import "HCDWaiter.h" #import "HCDCustomr.h" #import "HCDWorker.h" + + @interface ViewController () @end @@ -18,12 +20,24 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - + //waiter用于接收各种类型的order。waiter是请求接收者。 + //接收不同customer产生的不同order,并且都存入waiter这个接受者中,type表示不同类型的order。 HCDWaiter *waiter = [[HCDWaiter alloc]init]; + //顾客一 HCDCustomr *customer = [[HCDCustomr alloc]init]; - [waiter addOrder:[customer pushOrderWithString:@"十串羊肉" type:YES]]; + HCDOrder *customerOrder1 = [customer pushOrderWithString:@"顾客一要十串羊肉" type:orderTypeMutton]; + HCDOrder *customerOrder2 = [customer pushOrderWithString:@"顾客一要十串鸭肉" type:orderTypeDuck]; + [waiter addOrder:customerOrder1]; + [waiter addOrder:customerOrder2]; + //顾客二 HCDCustomr *customer1 = [[HCDCustomr alloc]init]; - [waiter addOrder:[customer1 pushOrderWithString:@"二十串鸡肉" type:NO]]; + HCDOrder *customer1Order1 = [customer1 pushOrderWithString:@"顾客二要二十串鸡肉" type:orderTypeChicken]; + HCDOrder *customer1Order2 = [customer1 pushOrderWithString:@"顾客二要二十串鸭肉" type:orderTypeDuck]; + [waiter addOrder:customer1Order1]; + [waiter addOrder:customer1Order2]; + //顾客取消Order + [waiter deleteOrder:customer1Order2]; + //waiter发送order,背后有一个HCDWorker这个单列作为行为实现者来处理具体的order。命令接收完毕,开始发送命令。 [waiter notifyOrder]; } diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/.DS_Store" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/.DS_Store" index b25f2cb..5a8e3ae 100644 Binary files "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/.DS_Store" and "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/.DS_Store" differ diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" index 21a32ab..c2c0458 100644 Binary files "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" and "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" differ diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" index 66c24d6..7ac7daf 100644 Binary files "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" and "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" differ diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" index cf1ee1a..16668e5 100644 --- "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" +++ "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" @@ -15,8 +15,8 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "44" endingLineNumber = "44" - landmarkName = "-calculate:" - landmarkType = "5"> + landmarkName = "@implementation ViewController" + landmarkType = "3"> + landmarkName = "numberA" + landmarkType = "24"> + + + + diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/CommonTool.h" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/CommonTool.h" index 9abc836..29dc685 100644 --- "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/CommonTool.h" +++ "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/CommonTool.h" @@ -9,7 +9,7 @@ #import typedef NS_ENUM(NSInteger, CalculateType){ - calcuteTypeAdd, + calcuteTypeAdd = 0, calcuteTypeMinus, calcuteTypdeMultipy, calcuteTypeDivide diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculate.h" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculate.h" index 41a665e..07267a2 100644 --- "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculate.h" +++ "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculate.h" @@ -8,9 +8,13 @@ #import #import +/** + * 协议声明出来的是方法,虽然看起来是属性,其实只有 getter、setter 这两个方法,内部是没有实例变量的,并且你不能去重定义它,只能在 getter、setter 里处理 + */ @protocol HCDCalculate @property(nonatomic)CGFloat numberA; @property(nonatomic)CGFloat numberB; + -(CGFloat)calculate; @end diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculateAdd.h" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculateAdd.h" index 64375cd..1acea14 100644 --- "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculateAdd.h" +++ "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculateAdd.h" @@ -8,6 +8,7 @@ #import #import "HCDCalculate.h" + @interface HCDCalculateAdd : NSObject @end diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculateAdd.m" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculateAdd.m" index 7f77064..5d20615 100644 --- "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculateAdd.m" +++ "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalculateAdd.m" @@ -8,8 +8,13 @@ #import "HCDCalculateAdd.h" @implementation HCDCalculateAdd + +/** + * 下面这两句话会自动生成实现的协议的属性对应的成员变量。如果没有这两句话,则系统会奔溃 + */ @synthesize numberA = _numberA; @synthesize numberB = _numberB; + -(CGFloat)calculate{ return self.numberA + self.numberB; } diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalcuteFactory.h" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalcuteFactory.h" index ce995a5..50379bf 100644 --- "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalcuteFactory.h" +++ "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalcuteFactory.h" @@ -8,8 +8,10 @@ #import #import "HCDCalculate.h" -#import "CommonTool.h" + + +@class CommonTool; @interface HCDCalcuteFactory : NSObject -+(id)createCalcute:(CalculateType)calculatetype; ++(id)createCalcute:(NSString *)calculatetype; @end diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalcuteFactory.m" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalcuteFactory.m" index 965b776..aa0cdf8 100644 --- "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalcuteFactory.m" +++ "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/HCDCalcuteFactory.m" @@ -11,11 +11,17 @@ #import "HCDCalculateDivide.h" #import "HCDCalculateMinus.h" #import "HCDCalcuteMultiply.h" +#import "CommonTool.h" @implementation HCDCalcuteFactory -+(id)createCalcute:(CalculateType)calculatetype{ - switch (calculatetype) { ++(id)createCalcute:(NSString *)calculatetype{ + + NSArray *calculateArray = @[@"+",@"-",@"*",@"/"]; + CalculateType calType = [calculateArray indexOfObject:calculatetype]; + + + switch (calType) { case calcuteTypeAdd: return [[HCDCalculateAdd alloc]init]; break; diff --git "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/ViewController.m" "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/ViewController.m" index 7a1e4aa..da2fd74 100644 --- "a/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/ViewController.m" +++ "b/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/1\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217/ViewController.m" @@ -7,8 +7,6 @@ // #import "ViewController.h" -#import "CommonTool.h" -#import "HCDCalculate.h" #import "HCDCalcuteFactory.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UITextField *numberA; @@ -29,15 +27,7 @@ - (void)viewDidLoad { - (IBAction)calculate:(id)sender { id cal; - if ([self.countTextField.text isEqualToString:@"+"]) { - cal =[HCDCalcuteFactory createCalcute:calcuteTypeAdd]; - }else if([self.countTextField.text isEqualToString:@"-"]){ - cal = [HCDCalcuteFactory createCalcute:calcuteTypeMinus]; - }else if ([self.countTextField.text isEqualToString:@"*"]) { - cal =[HCDCalcuteFactory createCalcute:calcuteTypdeMultipy]; - }else if([self.countTextField.text isEqualToString:@"/"]){ - cal = [HCDCalcuteFactory createCalcute:calcuteTypeDivide]; - } + cal =[HCDCalcuteFactory createCalcute:self.countTextField.text]; cal.numberA = [self.numberA.text floatValue]; cal.numberB = [self.numberB.text floatValue]; CGFloat result = [cal calculate]; diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" index 6058897..fada9bf 100644 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" @@ -8,11 +8,11 @@ /* Begin PBXBuildFile section */ 4D008F541B8DF5A7003CA07A /* 中介者模式.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D008F531B8DF5A7003CA07A /* 中介者模式.png */; }; - 4D008F581B8DF81A003CA07A /* HCDAbstractColleague.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D008F571B8DF81A003CA07A /* HCDAbstractColleague.m */; }; - 4D008F5F1B8DFA90003CA07A /* HCDMediator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D008F5E1B8DFA90003CA07A /* HCDMediator.m */; }; - 4D008F621B8DFADB003CA07A /* HCDColleagueA.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D008F611B8DFADB003CA07A /* HCDColleagueA.m */; }; - 4D008F651B8DFAEB003CA07A /* HCDColleagueB.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D008F641B8DFAEB003CA07A /* HCDColleagueB.m */; }; - 4D008F681B8E0275003CA07A /* HCDAbstractMediator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D008F671B8E0275003CA07A /* HCDAbstractMediator.m */; }; + 4D0B4E1A1ED2D82400BB8AA0 /* Mediator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D0B4E191ED2D82400BB8AA0 /* Mediator.m */; }; + 4D0B4E1D1ED2D83700BB8AA0 /* Colleague.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D0B4E1C1ED2D83700BB8AA0 /* Colleague.m */; }; + 4D0B4E201ED2D8EA00BB8AA0 /* ConcreteMediator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D0B4E1F1ED2D8EA00BB8AA0 /* ConcreteMediator.m */; }; + 4D0B4E231ED2D95000BB8AA0 /* ConcreteColleague1.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D0B4E221ED2D95000BB8AA0 /* ConcreteColleague1.m */; }; + 4D0B4E261ED2D95C00BB8AA0 /* ConcreteColleague2.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D0B4E251ED2D95C00BB8AA0 /* ConcreteColleague2.m */; }; DD2D69711B7F409900F9E848 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D69701B7F409900F9E848 /* main.m */; }; DD2D69741B7F409900F9E848 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D69731B7F409900F9E848 /* AppDelegate.m */; }; DD2D69771B7F409900F9E848 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2D69761B7F409900F9E848 /* ViewController.m */; }; @@ -34,16 +34,16 @@ /* Begin PBXFileReference section */ 4D008F531B8DF5A7003CA07A /* 中介者模式.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "中介者模式.png"; sourceTree = ""; }; - 4D008F561B8DF81A003CA07A /* HCDAbstractColleague.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDAbstractColleague.h; sourceTree = ""; }; - 4D008F571B8DF81A003CA07A /* HCDAbstractColleague.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDAbstractColleague.m; sourceTree = ""; }; - 4D008F5D1B8DFA90003CA07A /* HCDMediator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDMediator.h; sourceTree = ""; }; - 4D008F5E1B8DFA90003CA07A /* HCDMediator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDMediator.m; sourceTree = ""; }; - 4D008F601B8DFADB003CA07A /* HCDColleagueA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDColleagueA.h; sourceTree = ""; }; - 4D008F611B8DFADB003CA07A /* HCDColleagueA.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDColleagueA.m; sourceTree = ""; }; - 4D008F631B8DFAEB003CA07A /* HCDColleagueB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDColleagueB.h; sourceTree = ""; }; - 4D008F641B8DFAEB003CA07A /* HCDColleagueB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDColleagueB.m; sourceTree = ""; }; - 4D008F661B8E0275003CA07A /* HCDAbstractMediator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDAbstractMediator.h; sourceTree = ""; }; - 4D008F671B8E0275003CA07A /* HCDAbstractMediator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDAbstractMediator.m; sourceTree = ""; }; + 4D0B4E181ED2D82400BB8AA0 /* Mediator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mediator.h; sourceTree = ""; }; + 4D0B4E191ED2D82400BB8AA0 /* Mediator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Mediator.m; sourceTree = ""; }; + 4D0B4E1B1ED2D83700BB8AA0 /* Colleague.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Colleague.h; sourceTree = ""; }; + 4D0B4E1C1ED2D83700BB8AA0 /* Colleague.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Colleague.m; sourceTree = ""; }; + 4D0B4E1E1ED2D8EA00BB8AA0 /* ConcreteMediator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcreteMediator.h; sourceTree = ""; }; + 4D0B4E1F1ED2D8EA00BB8AA0 /* ConcreteMediator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcreteMediator.m; sourceTree = ""; }; + 4D0B4E211ED2D95000BB8AA0 /* ConcreteColleague1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcreteColleague1.h; sourceTree = ""; }; + 4D0B4E221ED2D95000BB8AA0 /* ConcreteColleague1.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcreteColleague1.m; sourceTree = ""; }; + 4D0B4E241ED2D95C00BB8AA0 /* ConcreteColleague2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcreteColleague2.h; sourceTree = ""; }; + 4D0B4E251ED2D95C00BB8AA0 /* ConcreteColleague2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcreteColleague2.m; sourceTree = ""; }; DD2D696B1B7F409900F9E848 /* 20中介者模式.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "20中介者模式.app"; sourceTree = BUILT_PRODUCTS_DIR; }; DD2D696F1B7F409900F9E848 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DD2D69701B7F409900F9E848 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -77,21 +77,37 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 4D008F551B8DF5B3003CA07A /* 终结者模式 */ = { + 4D0B4E101ED2D1B800BB8AA0 /* 中介者模式 */ = { isa = PBXGroup; children = ( - 4D008F561B8DF81A003CA07A /* HCDAbstractColleague.h */, - 4D008F571B8DF81A003CA07A /* HCDAbstractColleague.m */, - 4D008F5D1B8DFA90003CA07A /* HCDMediator.h */, - 4D008F5E1B8DFA90003CA07A /* HCDMediator.m */, - 4D008F601B8DFADB003CA07A /* HCDColleagueA.h */, - 4D008F611B8DFADB003CA07A /* HCDColleagueA.m */, - 4D008F631B8DFAEB003CA07A /* HCDColleagueB.h */, - 4D008F641B8DFAEB003CA07A /* HCDColleagueB.m */, - 4D008F661B8E0275003CA07A /* HCDAbstractMediator.h */, - 4D008F671B8E0275003CA07A /* HCDAbstractMediator.m */, + 4D0B4E121ED2D1D500BB8AA0 /* Colleague */, + 4D0B4E111ED2D1CB00BB8AA0 /* Mediator */, ); - name = "终结者模式"; + name = "中介者模式"; + sourceTree = ""; + }; + 4D0B4E111ED2D1CB00BB8AA0 /* Mediator */ = { + isa = PBXGroup; + children = ( + 4D0B4E181ED2D82400BB8AA0 /* Mediator.h */, + 4D0B4E191ED2D82400BB8AA0 /* Mediator.m */, + 4D0B4E1E1ED2D8EA00BB8AA0 /* ConcreteMediator.h */, + 4D0B4E1F1ED2D8EA00BB8AA0 /* ConcreteMediator.m */, + ); + name = Mediator; + sourceTree = ""; + }; + 4D0B4E121ED2D1D500BB8AA0 /* Colleague */ = { + isa = PBXGroup; + children = ( + 4D0B4E1B1ED2D83700BB8AA0 /* Colleague.h */, + 4D0B4E1C1ED2D83700BB8AA0 /* Colleague.m */, + 4D0B4E211ED2D95000BB8AA0 /* ConcreteColleague1.h */, + 4D0B4E221ED2D95000BB8AA0 /* ConcreteColleague1.m */, + 4D0B4E241ED2D95C00BB8AA0 /* ConcreteColleague2.h */, + 4D0B4E251ED2D95C00BB8AA0 /* ConcreteColleague2.m */, + ); + name = Colleague; sourceTree = ""; }; DD2D69621B7F409900F9E848 = { @@ -115,7 +131,7 @@ DD2D696D1B7F409900F9E848 /* 20中介者模式 */ = { isa = PBXGroup; children = ( - 4D008F551B8DF5B3003CA07A /* 终结者模式 */, + 4D0B4E101ED2D1B800BB8AA0 /* 中介者模式 */, 4D008F531B8DF5A7003CA07A /* 中介者模式.png */, DD2D69721B7F409900F9E848 /* AppDelegate.h */, DD2D69731B7F409900F9E848 /* AppDelegate.m */, @@ -256,14 +272,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4D008F681B8E0275003CA07A /* HCDAbstractMediator.m in Sources */, - 4D008F5F1B8DFA90003CA07A /* HCDMediator.m in Sources */, DD2D69771B7F409900F9E848 /* ViewController.m in Sources */, - 4D008F581B8DF81A003CA07A /* HCDAbstractColleague.m in Sources */, - 4D008F621B8DFADB003CA07A /* HCDColleagueA.m in Sources */, + 4D0B4E231ED2D95000BB8AA0 /* ConcreteColleague1.m in Sources */, DD2D69741B7F409900F9E848 /* AppDelegate.m in Sources */, + 4D0B4E1D1ED2D83700BB8AA0 /* Colleague.m in Sources */, + 4D0B4E1A1ED2D82400BB8AA0 /* Mediator.m in Sources */, + 4D0B4E261ED2D95C00BB8AA0 /* ConcreteColleague2.m in Sources */, DD2D69711B7F409900F9E848 /* main.m in Sources */, - 4D008F651B8DFAEB003CA07A /* HCDColleagueB.m in Sources */, + 4D0B4E201ED2D8EA00BB8AA0 /* ConcreteMediator.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" index b7dc735..eb4191a 100644 Binary files "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" and "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" differ diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Colleague.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Colleague.h" new file mode 100644 index 0000000..124b02b --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Colleague.h" @@ -0,0 +1,20 @@ +// +// Colleague.h +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import + +@class Mediator; +@interface Colleague : NSObject + +@property(nonatomic, strong)Mediator *mediator; + +-(instancetype)initWithMediator:(Mediator *)mediator; + +-(void)notify:(NSString *)message; +-(void)send:(NSString *)message; +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Colleague.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Colleague.m" new file mode 100644 index 0000000..050320d --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Colleague.m" @@ -0,0 +1,13 @@ +// +// Colleague.m +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Colleague.h" + +@implementation Colleague + +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague1.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague1.h" new file mode 100644 index 0000000..284b72b --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague1.h" @@ -0,0 +1,13 @@ +// +// ConcreteColleague1.h +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Colleague.h" + +@interface ConcreteColleague1 : Colleague + +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague1.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague1.m" new file mode 100644 index 0000000..01dbe3a --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague1.m" @@ -0,0 +1,33 @@ +// +// ConcreteColleague1.m +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "ConcreteColleague1.h" +#import "Mediator.h" + +@implementation ConcreteColleague1 + +@synthesize mediator = _mediator; + +-(instancetype)initWithMediator:(Mediator *)mediator{ + self = [super init]; + if (self) { + _mediator = mediator; + } + return self; +} + +-(void)send:(NSString *)message{ + NSLog(@"同事1发送了信息"); + [_mediator send:message colleague:self]; +} + +-(void)notify:(NSString *)message{ + NSLog(@"%@%@",@"同事1得到消息:", message); +} + +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague2.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague2.h" new file mode 100644 index 0000000..d9d44cf --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague2.h" @@ -0,0 +1,13 @@ +// +// ConcreteColleague2.h +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Colleague.h" + +@interface ConcreteColleague2 : Colleague + +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague2.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague2.m" new file mode 100644 index 0000000..b79975d --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteColleague2.m" @@ -0,0 +1,31 @@ +// +// ConcreteColleague2.m +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "ConcreteColleague2.h" +#import "Mediator.h" + +@implementation ConcreteColleague2 +@synthesize mediator = _mediator; + +-(instancetype)initWithMediator:(Mediator *)mediator{ + self = [super init]; + if (self) { + _mediator = mediator; + } + return self; +} + +-(void)send:(NSString *)message{ + NSLog(@"同事2发送了信息"); + [_mediator send:message colleague:self]; +} + +-(void)notify:(NSString *)message{ + NSLog(@"%@%@",@"同事2得到消息", message); +} +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteMediator.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteMediator.h" new file mode 100644 index 0000000..1e52439 --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteMediator.h" @@ -0,0 +1,17 @@ +// +// ConcreteMediator.h +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Mediator.h" + +@class Colleague; + +@interface ConcreteMediator : Mediator + + + +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteMediator.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteMediator.m" new file mode 100644 index 0000000..810869a --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ConcreteMediator.m" @@ -0,0 +1,25 @@ +// +// ConcreteMediator.m +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "ConcreteMediator.h" +#import "ConcreteColleague1.h" +#import "ConcreteColleague2.h" + +@implementation ConcreteMediator +@synthesize colleague1 =_colleague1; +@synthesize colleague2 = _colleague2; + +-(void)send:(NSString *)message colleague:(Colleague *)colleague{ + if (colleague == _colleague1) { + [_colleague2 notify:message]; + }else{ + [_colleague1 notify:message]; + } +} + +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractColleague.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractColleague.h" deleted file mode 100644 index 8f77119..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractColleague.h" +++ /dev/null @@ -1,16 +0,0 @@ -// -// HCDAbstractColleague.h -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import -#import -@class HCDAbstractMediator; -@interface HCDAbstractColleague : NSObject -@property(nonatomic,assign)CGFloat number; --(void)notice; -@property(nonatomic,strong) HCDAbstractMediator *mediator; -@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractColleague.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractColleague.m" deleted file mode 100644 index e7cb440..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractColleague.m" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDAbstractColleague.m -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDAbstractColleague.h" -#import "HCDAbstractMediator.h" -@implementation HCDAbstractColleague - -@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractMediator.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractMediator.h" deleted file mode 100644 index 87e5f6e..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractMediator.h" +++ /dev/null @@ -1,19 +0,0 @@ -// -// HCDAbstractMediator.h -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import -#import "HCDColleagueB.h" -#import "HCDColleagueA.h" -@interface HCDAbstractMediator : NSObject --(instancetype)initWithColleagueA:(HCDAbstractColleague *)colleagueA colleagueB:(HCDAbstractColleague *)colleagueB; -@property(nonatomic,weak)HCDAbstractColleague *colleagueA; -@property(nonatomic,weak)HCDAbstractColleague *colleagueB; --(void)setValueToColleagueA:(CGFloat)value; --(void)setValueToColleagueB:(CGFloat)value; -@end - diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractMediator.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractMediator.m" deleted file mode 100644 index e95e4ac..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDAbstractMediator.m" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDAbstractMediator.m -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDAbstractMediator.h" - -@implementation HCDAbstractMediator - -@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueA.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueA.h" deleted file mode 100644 index adfd6b9..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueA.h" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDColleagueA.h -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDAbstractColleague.h" - -@interface HCDColleagueA : HCDAbstractColleague - -@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueA.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueA.m" deleted file mode 100644 index e41b1ff..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueA.m" +++ /dev/null @@ -1,15 +0,0 @@ -// -// HCDColleagueA.m -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDColleagueA.h" -#import "HCDAbstractMediator.h" -@implementation HCDColleagueA --(void)notice{ - [self.mediator setValueToColleagueB:self.number]; -} -@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueB.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueB.h" deleted file mode 100644 index 67459e1..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueB.h" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDColleagueB.h -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDAbstractColleague.h" - -@interface HCDColleagueB : HCDAbstractColleague - -@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueB.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueB.m" deleted file mode 100644 index f9dfc11..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDColleagueB.m" +++ /dev/null @@ -1,15 +0,0 @@ -// -// HCDColleagueB.m -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDColleagueB.h" -#import "HCDAbstractMediator.h" -@implementation HCDColleagueB --(void)notice{ - [self.mediator setValueToColleagueA:self.number]; -} -@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDMediator.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDMediator.h" deleted file mode 100644 index 475bf90..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDMediator.h" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDMediator.h -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import -#import "HCDAbstractMediator.h" -@interface HCDMediator : HCDAbstractMediator - -@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDMediator.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDMediator.m" deleted file mode 100644 index 5c5ed5e..0000000 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/HCDMediator.m" +++ /dev/null @@ -1,31 +0,0 @@ -// -// HCDMediator.m -// 20中介者模式 -// -// Created by 黄成都 on 15/8/26. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDMediator.h" - -@implementation HCDMediator -@synthesize colleagueB = _colleagueB; -@synthesize colleagueA = _colleagueA; - --(instancetype)initWithColleagueA:(HCDAbstractColleague *)colleagueA colleagueB:(HCDAbstractColleague *)colleagueB{ - self = [super init]; - if (self) { - _colleagueA = colleagueA; - _colleagueB = colleagueB; - } - return self; -} - - --(void)setValueToColleagueA:(CGFloat)value{ - self.colleagueA.number = value * 100; -} --(void)setValueToColleagueB:(CGFloat)value{ - self.colleagueB.number = value * 0.01; -} -@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Mediator.h" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Mediator.h" new file mode 100644 index 0000000..ddbe2b6 --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Mediator.h" @@ -0,0 +1,21 @@ +// +// Mediator.h +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import + +@class Colleague; + +@interface Mediator : NSObject + +@property(nonatomic, strong)Colleague *colleague1; +@property(nonatomic, strong)Colleague *colleague2; + +-(void)send:(NSString *)message colleague:(Colleague *)colleague; + + +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Mediator.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Mediator.m" new file mode 100644 index 0000000..e9ca05f --- /dev/null +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/Mediator.m" @@ -0,0 +1,13 @@ +// +// Mediator.m +// 20中介者模式 +// +// Created by huangchengdu on 17/5/22. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Mediator.h" + +@implementation Mediator + +@end diff --git "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ViewController.m" "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ViewController.m" index 99464d2..8b12d27 100644 --- "a/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ViewController.m" +++ "b/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/20\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217/ViewController.m" @@ -7,10 +7,11 @@ // #import "ViewController.h" -#import "HCDColleagueA.h" -#import "HCDColleagueB.h" -#import "HCDAbstractMediator.h" -#import "HCDMediator.h" +#import "ConcreteColleague1.h" +#import "ConcreteColleague2.h" +#import "ConcreteMediator.h" + + @interface ViewController () @end @@ -19,27 +20,18 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; + //初始化一个中介者对象 + ConcreteMediator *mediator = [[ConcreteMediator alloc]init]; + //初始化并且让两个同事有相同的中介者对象 + ConcreteColleague1 *c1 = [[ConcreteColleague1 alloc]initWithMediator:mediator]; + ConcreteColleague2 *c2 = [[ConcreteColleague2 alloc]initWithMediator:mediator]; + //给中介者对象绑定两个要交互的同事对象 + mediator.colleague1 = c1; + mediator.colleague2 = c2; + [c1 send:@"吃过饭了吗?"]; + [c2 send:@"没有呢,你打算请客?"]; - HCDAbstractColleague *colleagueA = [[HCDColleagueA alloc]init]; - HCDAbstractColleague *colleagueB = [[HCDColleagueB alloc]init]; - - HCDAbstractMediator *mediator = [[HCDMediator alloc]initWithColleagueA:colleagueA colleagueB:colleagueB]; - colleagueA.mediator = mediator; - colleagueB.mediator = mediator; - - colleagueA.number = 1450; - colleagueB.number = 1450; - [colleagueA notice]; - NSLog(@"%f---%f",colleagueA.number,colleagueB.number); - colleagueB.number = 123; - [colleagueB notice]; - NSLog(@"%f---%f",colleagueA.number,colleagueB.number); -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. } @end diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" index 6ea5638..b114513 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.xcodeproj/project.pbxproj" @@ -81,6 +81,32 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4D1868E71ED82CFC00F8C3C0 /* element */ = { + isa = PBXGroup; + children = ( + 4DC842111B8F46B500DD1E28 /* HCDElements.h */, + 4DC842121B8F46B500DD1E28 /* HCDElements.m */, + 4DC842141B8F471A00DD1E28 /* HCDConcreteElementA.h */, + 4DC842151B8F471A00DD1E28 /* HCDConcreteElementA.m */, + 4DC842171B8F478600DD1E28 /* HCDConcreteElementB.h */, + 4DC842181B8F478600DD1E28 /* HCDConcreteElementB.m */, + ); + name = element; + sourceTree = ""; + }; + 4D1868E81ED82D0500F8C3C0 /* visitor */ = { + isa = PBXGroup; + children = ( + 4DC842081B8F462900DD1E28 /* HCDVisitors.h */, + 4DC842091B8F462900DD1E28 /* HCDVisitors.m */, + 4DC8420B1B8F465A00DD1E28 /* HCDConcreteVisitor1.h */, + 4DC8420C1B8F465A00DD1E28 /* HCDConcreteVisitor1.m */, + 4DC8420E1B8F467100DD1E28 /* HCDConcreteVisitor2.h */, + 4DC8420F1B8F467100DD1E28 /* HCDConcreteVisitor2.m */, + ); + name = visitor; + sourceTree = ""; + }; 4DC841D51B8F45D500DD1E28 = { isa = PBXGroup; children = ( @@ -144,18 +170,8 @@ 4DC842071B8F45DF00DD1E28 /* 访问者模式 */ = { isa = PBXGroup; children = ( - 4DC842081B8F462900DD1E28 /* HCDVisitors.h */, - 4DC842091B8F462900DD1E28 /* HCDVisitors.m */, - 4DC8420B1B8F465A00DD1E28 /* HCDConcreteVisitor1.h */, - 4DC8420C1B8F465A00DD1E28 /* HCDConcreteVisitor1.m */, - 4DC8420E1B8F467100DD1E28 /* HCDConcreteVisitor2.h */, - 4DC8420F1B8F467100DD1E28 /* HCDConcreteVisitor2.m */, - 4DC842111B8F46B500DD1E28 /* HCDElements.h */, - 4DC842121B8F46B500DD1E28 /* HCDElements.m */, - 4DC842141B8F471A00DD1E28 /* HCDConcreteElementA.h */, - 4DC842151B8F471A00DD1E28 /* HCDConcreteElementA.m */, - 4DC842171B8F478600DD1E28 /* HCDConcreteElementB.h */, - 4DC842181B8F478600DD1E28 /* HCDConcreteElementB.m */, + 4D1868E81ED82D0500F8C3C0 /* visitor */, + 4D1868E71ED82CFC00F8C3C0 /* element */, 4DC8421A1B8F482600DD1E28 /* HCDObjectStructure.h */, 4DC8421B1B8F482600DD1E28 /* HCDObjectStructure.m */, ); @@ -466,6 +482,7 @@ 4DC842031B8F45D500DD1E28 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 4DC842041B8F45D500DD1E28 /* Build configuration list for PBXNativeTarget "23访问者模式Tests" */ = { isa = XCConfigurationList; @@ -474,6 +491,7 @@ 4DC842061B8F45D500DD1E28 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" index ebf6d16..43fb609 100644 Binary files "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" and "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" differ diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteElementA.m" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteElementA.m" index 4731e09..fddc385 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteElementA.m" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteElementA.m" @@ -8,11 +8,14 @@ #import "HCDConcreteElementA.h" #import "HCDVisitors.h" + + @implementation HCDConcreteElementA + -(void)operationA{ return; } -(void)accept:(HCDVisitors *)visitor{ - [visitor VisitConcreteElementA:self]; + [visitor visitConcreteElementA:self]; } @end diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteElementB.m" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteElementB.m" index f3f0347..3a5e0e6 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteElementB.m" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteElementB.m" @@ -8,11 +8,14 @@ #import "HCDConcreteElementB.h" #import "HCDVisitors.h" + + @implementation HCDConcreteElementB + -(void)operationB{ return; } -(void)accept:(HCDVisitors *)visitor{ - [visitor VisitConcreteElementB:self]; + [visitor visitConcreteElementB:self]; } @end diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteVisitor1.m" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteVisitor1.m" index 6c47534..58216b7 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteVisitor1.m" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteVisitor1.m" @@ -7,14 +7,16 @@ // #import "HCDConcreteVisitor1.h" -#import "HCDConcreteElementA.h" + + @implementation HCDConcreteVisitor1 --(void)VisitConcreteElementA:(HCDConcreteElementA *)concreteElementA{ - NSString *eleName = NSStringFromClass([concreteElementA class]); - - NSString *visitorName = NSStringFromClass([self class]); - - NSLog(@"%@被%@访问",eleName, visitorName); + +-(void)visitConcreteElementA:(HCDConcreteElementA *)concreteElementA{ + NSLog(@"男人接收到喜这个visitor============我要飞"); +} + +-(void)visitConcreteElementB:(HCDConcreteElementB *)concreteElementB{ + NSLog(@"女人接收到喜这个visitor============我要跳"); } @end diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteVisitor2.m" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteVisitor2.m" index 6098624..d361226 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteVisitor2.m" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDConcreteVisitor2.m" @@ -7,13 +7,14 @@ // #import "HCDConcreteVisitor2.h" -#import "HCDConcreteElementB.h" + @implementation HCDConcreteVisitor2 --(void)VisitConcreteElementB:(HCDConcreteElementB *)concreteElementB{ - NSString *eleName = NSStringFromClass([concreteElementB class]); - - NSString *visitorName = NSStringFromClass([self class]); - - NSLog(@"%@被%@访问",eleName, visitorName); + +-(void)visitConcreteElementA:(HCDConcreteElementA *)concreteElementA{ + NSLog(@"男人接收到怒这个visitor============我要叫"); +} + +-(void)visitConcreteElementB:(HCDConcreteElementB *)concreteElementB{ + NSLog(@"女人接收到怒这个visitor============我要苦"); } @end diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDElements.h" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDElements.h" index ce3e903..676ae6d 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDElements.h" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDElements.h" @@ -7,7 +7,9 @@ // #import + @class HCDVisitors; + @interface HCDElements : NSObject -(void)accept:(HCDVisitors *)visitor; @end diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDObjectStructure.h" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDObjectStructure.h" index 62c79b9..7afc97f 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDObjectStructure.h" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDObjectStructure.h" @@ -7,13 +7,17 @@ // #import + @class HCDElements; @class HCDVisitors; + @interface HCDObjectStructure : NSObject { NSMutableArray *elements; } +//添加和删除element -(void)attach:(HCDElements *)element; -(void)detach:(HCDElements *)element; +//接受一个visitor -(void)accept:(HCDVisitors *)visitor; @end diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDObjectStructure.m" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDObjectStructure.m" index ea5ef8f..fbca5c7 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDObjectStructure.m" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDObjectStructure.m" @@ -9,7 +9,9 @@ #import "HCDObjectStructure.h" #import "HCDElements.h" #import "HCDVisitors.h" + @implementation HCDObjectStructure + -(instancetype)init{ self = [super init]; if (self) { @@ -17,12 +19,15 @@ -(instancetype)init{ } return self; } + -(void)attach:(HCDElements *)element{ [elements addObject:element]; } + -(void)detach:(HCDElements *)element{ [elements removeObject:element]; } + -(void)accept:(HCDVisitors *)visitor{ for (HCDElements *e in elements) { [e accept:visitor]; diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDVisitors.h" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDVisitors.h" index bd01869..9085861 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDVisitors.h" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDVisitors.h" @@ -7,9 +7,14 @@ // #import -@class HCDConcreteElementA,HCDConcreteElementB; +#import "HCDConcreteElementA.h" +#import "HCDConcreteElementB.h" + + @interface HCDVisitors : NSObject --(void)VisitConcreteElementA:(HCDConcreteElementA *)concreteElementA; --(void)VisitConcreteElementB:(HCDConcreteElementB *)concreteElementB; + + +-(void)visitConcreteElementA:(HCDConcreteElementA *)concreteElementA; +-(void)visitConcreteElementB:(HCDConcreteElementB *)concreteElementB; @end diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDVisitors.m" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDVisitors.m" index 7d910f3..3a8fffe 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDVisitors.m" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/HCDVisitors.m" @@ -9,11 +9,13 @@ #import "HCDVisitors.h" #import "HCDConcreteElementA.h" #import "HCDConcreteElementB.h" + @implementation HCDVisitors --(void)VisitConcreteElementA:(HCDConcreteElementA *)concreteElementA{ + +-(void)visitConcreteElementA:(HCDConcreteElementA *)concreteElementA{ return; } --(void)VisitConcreteElementB:(HCDConcreteElementB *)concreteElementB{ +-(void)visitConcreteElementB:(HCDConcreteElementB *)concreteElementB{ return; } @end diff --git "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/ViewController.m" "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/ViewController.m" index 9d67c28..45e5a77 100644 --- "a/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/ViewController.m" +++ "b/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/23\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217/ViewController.m" @@ -20,24 +20,25 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; + /* + HCDConcreteElementA和HCDConcreteElementB相当于男人女人(固定不变),当男人女人接收到喜怒哀乐(HCDConcreteVisitor1,HCDConcreteVisitor2)有不同的结果。HCDObjectStructure用于管理他们之间的关系。 + */ HCDObjectStructure *o = [[HCDObjectStructure alloc]init]; + //初始化不同的element对象 HCDConcreteElementA *eA = [HCDConcreteElementA new]; - HCDConcreteElementB *eB = [HCDConcreteElementB new]; - + //加入o对象里面,存在一个数据结构o中。 [o attach:eA]; - [o attach:eB]; - HCDConcreteVisitor1 - *v1 = [HCDConcreteVisitor1 new]; - - HCDConcreteVisitor2 - *v2 = [HCDConcreteVisitor2 new]; - + //初始化不同的visitor对象。 + HCDConcreteVisitor1 *v1 = [HCDConcreteVisitor1 new]; + HCDConcreteVisitor2 *v2 = [HCDConcreteVisitor2 new]; + //eA,eB(男人女人)接收到访问者v1(喜)的不同反应。 [o accept: v1]; - + NSLog(@"================================"); + //eA,eB(男人女人)接收到访问者v2(怒)的不同反应。 [o accept: v2]; } diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/project.pbxproj" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/project.pbxproj" new file mode 100644 index 0000000..f8d2726 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/project.pbxproj" @@ -0,0 +1,341 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 4DC94D291ECB1E7700A8DB96 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94D281ECB1E7700A8DB96 /* main.m */; }; + 4DC94D2C1ECB1E7700A8DB96 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94D2B1ECB1E7700A8DB96 /* AppDelegate.m */; }; + 4DC94D2F1ECB1E7700A8DB96 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94D2E1ECB1E7700A8DB96 /* ViewController.m */; }; + 4DC94D321ECB1E7700A8DB96 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4DC94D301ECB1E7700A8DB96 /* Main.storyboard */; }; + 4DC94D341ECB1E7700A8DB96 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4DC94D331ECB1E7700A8DB96 /* Assets.xcassets */; }; + 4DC94D371ECB1E7700A8DB96 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4DC94D351ECB1E7700A8DB96 /* LaunchScreen.storyboard */; }; + 4DC94D421ECB20C200A8DB96 /* Verter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94D411ECB20C200A8DB96 /* Verter.m */; }; + 4DC94D451ECB2B6E00A8DB96 /* Dot.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94D441ECB2B6E00A8DB96 /* Dot.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 4DC94D241ECB1E7700A8DB96 /* 24原型模式.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "24原型模式.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4DC94D281ECB1E7700A8DB96 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 4DC94D2A1ECB1E7700A8DB96 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 4DC94D2B1ECB1E7700A8DB96 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 4DC94D2D1ECB1E7700A8DB96 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 4DC94D2E1ECB1E7700A8DB96 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 4DC94D311ECB1E7700A8DB96 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 4DC94D331ECB1E7700A8DB96 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 4DC94D361ECB1E7700A8DB96 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 4DC94D381ECB1E7700A8DB96 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 4DC94D3F1ECB208400A8DB96 /* Mark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mark.h; sourceTree = ""; }; + 4DC94D401ECB20C200A8DB96 /* Verter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Verter.h; sourceTree = ""; }; + 4DC94D411ECB20C200A8DB96 /* Verter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Verter.m; sourceTree = ""; }; + 4DC94D431ECB2B6E00A8DB96 /* Dot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Dot.h; sourceTree = ""; }; + 4DC94D441ECB2B6E00A8DB96 /* Dot.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Dot.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4DC94D211ECB1E7700A8DB96 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4DC94D1B1ECB1E7700A8DB96 = { + isa = PBXGroup; + children = ( + 4DC94D261ECB1E7700A8DB96 /* 24原型模式 */, + 4DC94D251ECB1E7700A8DB96 /* Products */, + ); + sourceTree = ""; + }; + 4DC94D251ECB1E7700A8DB96 /* Products */ = { + isa = PBXGroup; + children = ( + 4DC94D241ECB1E7700A8DB96 /* 24原型模式.app */, + ); + name = Products; + sourceTree = ""; + }; + 4DC94D261ECB1E7700A8DB96 /* 24原型模式 */ = { + isa = PBXGroup; + children = ( + 4DC94D3E1ECB1F9B00A8DB96 /* 原型模式 */, + 4DC94D2A1ECB1E7700A8DB96 /* AppDelegate.h */, + 4DC94D2B1ECB1E7700A8DB96 /* AppDelegate.m */, + 4DC94D2D1ECB1E7700A8DB96 /* ViewController.h */, + 4DC94D2E1ECB1E7700A8DB96 /* ViewController.m */, + 4DC94D301ECB1E7700A8DB96 /* Main.storyboard */, + 4DC94D331ECB1E7700A8DB96 /* Assets.xcassets */, + 4DC94D351ECB1E7700A8DB96 /* LaunchScreen.storyboard */, + 4DC94D381ECB1E7700A8DB96 /* Info.plist */, + 4DC94D271ECB1E7700A8DB96 /* Supporting Files */, + ); + path = "24原型模式"; + sourceTree = ""; + }; + 4DC94D271ECB1E7700A8DB96 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 4DC94D281ECB1E7700A8DB96 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 4DC94D3E1ECB1F9B00A8DB96 /* 原型模式 */ = { + isa = PBXGroup; + children = ( + 4DC94D3F1ECB208400A8DB96 /* Mark.h */, + 4DC94D401ECB20C200A8DB96 /* Verter.h */, + 4DC94D411ECB20C200A8DB96 /* Verter.m */, + 4DC94D431ECB2B6E00A8DB96 /* Dot.h */, + 4DC94D441ECB2B6E00A8DB96 /* Dot.m */, + ); + name = "原型模式"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4DC94D231ECB1E7700A8DB96 /* 24原型模式 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4DC94D3B1ECB1E7700A8DB96 /* Build configuration list for PBXNativeTarget "24原型模式" */; + buildPhases = ( + 4DC94D201ECB1E7700A8DB96 /* Sources */, + 4DC94D211ECB1E7700A8DB96 /* Frameworks */, + 4DC94D221ECB1E7700A8DB96 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "24原型模式"; + productName = "24原型模式"; + productReference = 4DC94D241ECB1E7700A8DB96 /* 24原型模式.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4DC94D1C1ECB1E7700A8DB96 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = huangchengdu; + TargetAttributes = { + 4DC94D231ECB1E7700A8DB96 = { + CreatedOnToolsVersion = 8.2.1; + DevelopmentTeam = F5L2MR9755; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 4DC94D1F1ECB1E7700A8DB96 /* Build configuration list for PBXProject "24原型模式" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 4DC94D1B1ECB1E7700A8DB96; + productRefGroup = 4DC94D251ECB1E7700A8DB96 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4DC94D231ECB1E7700A8DB96 /* 24原型模式 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4DC94D221ECB1E7700A8DB96 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4DC94D371ECB1E7700A8DB96 /* LaunchScreen.storyboard in Resources */, + 4DC94D341ECB1E7700A8DB96 /* Assets.xcassets in Resources */, + 4DC94D321ECB1E7700A8DB96 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4DC94D201ECB1E7700A8DB96 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4DC94D2F1ECB1E7700A8DB96 /* ViewController.m in Sources */, + 4DC94D2C1ECB1E7700A8DB96 /* AppDelegate.m in Sources */, + 4DC94D291ECB1E7700A8DB96 /* main.m in Sources */, + 4DC94D451ECB2B6E00A8DB96 /* Dot.m in Sources */, + 4DC94D421ECB20C200A8DB96 /* Verter.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 4DC94D301ECB1E7700A8DB96 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 4DC94D311ECB1E7700A8DB96 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 4DC94D351ECB1E7700A8DB96 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 4DC94D361ECB1E7700A8DB96 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 4DC94D391ECB1E7700A8DB96 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 4DC94D3A1ECB1E7700A8DB96 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 4DC94D3C1ECB1E7700A8DB96 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = F5L2MR9755; + INFOPLIST_FILE = "24原型模式/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "www.ctrip.cpm.-4----"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 4DC94D3D1ECB1E7700A8DB96 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = F5L2MR9755; + INFOPLIST_FILE = "24原型模式/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "www.ctrip.cpm.-4----"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4DC94D1F1ECB1E7700A8DB96 /* Build configuration list for PBXProject "24原型模式" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4DC94D391ECB1E7700A8DB96 /* Debug */, + 4DC94D3A1ECB1E7700A8DB96 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4DC94D3B1ECB1E7700A8DB96 /* Build configuration list for PBXNativeTarget "24原型模式" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4DC94D3C1ECB1E7700A8DB96 /* Debug */, + 4DC94D3D1ECB1E7700A8DB96 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 4DC94D1C1ECB1E7700A8DB96 /* Project object */; +} diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/project.xcworkspace/contents.xcworkspacedata" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/project.xcworkspace/contents.xcworkspacedata" new file mode 100644 index 0000000..d925aac --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/project.xcworkspace/contents.xcworkspacedata" @@ -0,0 +1,7 @@ + + + + + diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" new file mode 100644 index 0000000..52f2ad4 Binary files /dev/null and "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/huangchengdu.xcuserdatad/UserInterfaceState.xcuserstate" differ diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" new file mode 100644 index 0000000..7404b02 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" @@ -0,0 +1,21 @@ + + + + + + + + + diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/24\345\216\237\345\236\213\346\250\241\345\274\217.xcscheme" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/24\345\216\237\345\236\213\346\250\241\345\274\217.xcscheme" new file mode 100644 index 0000000..70a9590 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/24\345\216\237\345\236\213\346\250\241\345\274\217.xcscheme" @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/xcschememanagement.plist" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/xcschememanagement.plist" new file mode 100644 index 0000000..399393d --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/xcschememanagement.plist" @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + 24原型模式.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 4DC94D231ECB1E7700A8DB96 + + primary + + + + + diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/AppDelegate.h" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/AppDelegate.h" new file mode 100644 index 0000000..6b8a6f4 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/AppDelegate.h" @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/AppDelegate.m" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/AppDelegate.m" new file mode 100644 index 0000000..44337bf --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/AppDelegate.m" @@ -0,0 +1,51 @@ +// +// AppDelegate.m +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + + +@end diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Assets.xcassets/AppIcon.appiconset/Contents.json" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Assets.xcassets/AppIcon.appiconset/Contents.json" new file mode 100644 index 0000000..36d2c80 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Assets.xcassets/AppIcon.appiconset/Contents.json" @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Base.lproj/LaunchScreen.storyboard" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Base.lproj/LaunchScreen.storyboard" new file mode 100644 index 0000000..fdf3f97 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Base.lproj/LaunchScreen.storyboard" @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Base.lproj/Main.storyboard" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Base.lproj/Main.storyboard" new file mode 100644 index 0000000..4529698 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Base.lproj/Main.storyboard" @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Dot.h" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Dot.h" new file mode 100644 index 0000000..78f6151 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Dot.h" @@ -0,0 +1,15 @@ +// +// Dot.h +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import +#import +#import "Mark.h" + +@interface Dot : NSObject + +@end diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Dot.m" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Dot.m" new file mode 100644 index 0000000..da2aae7 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Dot.m" @@ -0,0 +1,68 @@ +// +// Dot.m +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import "Dot.h" + +@interface Dot () +@property(nonatomic,copy)NSMutableArray *children; +@end + +@implementation Dot +@synthesize color = _color; +@synthesize size = _size; +@synthesize location = _location; +@synthesize count = _count; +@synthesize lastChild = _lastChild; + + +-(id)initWithLocation:(CGPoint)location{ + self = [super init]; + if (self) { + _location = location; + _children = [NSMutableArray arrayWithCapacity:5]; + } + return self; +} + +-(NSUInteger)count{ + return [_children count]; +} + +-(void)addMark:(id)mark{ + [self.children addObject:mark]; +} + +-(void)removeMark:(id)mark{ + if ([self.children containsObject:mark]) { + [self.children removeObject:mark]; + } +} + +-(id)childMarkAtIndex:(NSUInteger)index{ + if (self.children.count <= index) { + return nil; + } + return self.children[index]; +} + +-(id)lastChild{ + return [self.children lastObject]; +} + +-(id)copyWithZone:(NSZone *)zone{ + Dot *dot = [[[self class] alloc] initWithLocation:_location]; + [dot setColor:[UIColor colorWithCGColor:[_color CGColor]]]; + [dot setSize:_size]; + for (id mark in self.children) { + id childCopy = [mark copy]; + [dot addMark:childCopy]; + } + return dot; +} + +@end diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Info.plist" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Info.plist" new file mode 100644 index 0000000..d052473 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Info.plist" @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Mark.h" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Mark.h" new file mode 100644 index 0000000..0bf4839 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Mark.h" @@ -0,0 +1,28 @@ +// +// Mark.h +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import +#import + + + + +@protocol Mark + +@property (nonatomic, strong) UIColor *color; +@property (nonatomic, assign) CGFloat size; +@property (nonatomic, assign) CGPoint location; +@property (nonatomic, assign, readonly) NSUInteger count; +@property (nonatomic,strong, readonly) id lastChild; + +-(id) initWithLocation:(CGPoint) location; +-(id)copy; +-(void) addMark:(id) mark; +-(void) removeMark:(id) mark; +-(id) childMarkAtIndex:(NSUInteger) index; +@end diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Verter.h" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Verter.h" new file mode 100644 index 0000000..7833039 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Verter.h" @@ -0,0 +1,17 @@ +// +// Verter.h +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import +#import +#import "Mark.h" + + +@interface Verter : NSObject + + +@end diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Verter.m" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Verter.m" new file mode 100644 index 0000000..13f396a --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/Verter.m" @@ -0,0 +1,50 @@ +// +// Verter.m +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import "Verter.h" +#import "Mark.h" + + +@interface Verter () + +@end + +@implementation Verter +@synthesize color = _color; +@synthesize size = _size; +@synthesize location = _location; +@synthesize count = _count; +@synthesize lastChild = _lastChild; + +-(id)initWithLocation:(CGPoint)location{ + self = [super init]; + if (self) { + _location = location; + } + return self; +} + +-(void)addMark:(id)mark{ + +} + +-(void)removeMark:(id)mark{ + +} + +-(id)childMarkAtIndex:(NSUInteger)index{ + + return nil; +} + +-(id)copyWithZone:(NSZone *)zone{ + Verter *verter = [[[self class] alloc] initWithLocation:_location]; + return verter; +} + +@end diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/ViewController.h" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/ViewController.h" new file mode 100644 index 0000000..f2d7f3f --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/ViewController.h" @@ -0,0 +1,15 @@ +// +// ViewController.h +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/ViewController.m" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/ViewController.m" new file mode 100644 index 0000000..bdf7d8e --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/ViewController.m" @@ -0,0 +1,53 @@ +// +// ViewController.m +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import "ViewController.h" +#import "Verter.h" +#import "Dot.h" + + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + Verter *verter1 = [[Verter alloc]initWithLocation:CGPointMake(10, 10)]; + Verter *verter2 = [verter1 copy]; + Verter *verter3 = [verter1 copy]; + Verter *verter4 = [verter1 copy]; + [verter4 setLocation:CGPointMake(50, 50)]; + + NSLog(@"verter1地址:%p,verter1地址:%p,verter1地址:%p,verter1地址:%p",verter1,verter2,verter3,verter4); + + NSLog(@"verter3的Location:%@,verter4的Location:%@",NSStringFromCGPoint(verter3.location),NSStringFromCGPoint(verter4.location)); + + Dot *dot1 = [[Dot alloc]initWithLocation:CGPointMake(100, 100)]; + [dot1 addMark:verter1]; + [dot1 addMark:verter2]; + [dot1 addMark:verter3]; + [dot1 addMark:verter4]; + + Dot *dot2 = [dot1 copy]; + + NSLog(@"========================================="); + NSLog(@"dot1的mark个数%ld,地址:%p",dot1.count,dot1); + NSLog(@"dot2的mark个数%ld,地址:%p",dot2.count,dot2); + [dot1 removeMark:verter1]; + NSLog(@"dot1的mark个数%ld,地址:%p",dot1.count,dot1); + NSLog(@"dot2的mark个数%ld,地址:%p",dot2.count,dot2); + +} + + + + +@end diff --git "a/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/main.m" "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/main.m" new file mode 100644 index 0000000..1b4d4f0 --- /dev/null +++ "b/24\345\216\237\345\236\213\346\250\241\345\274\217/24\345\216\237\345\236\213\346\250\241\345\274\217/main.m" @@ -0,0 +1,16 @@ +// +// main.m +// 24原型模式 +// +// Created by huangchengdu on 17/5/16. +// Copyright © 2017年 huangchengdu. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/.DS_Store" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/.DS_Store" index b3c6d85..82f2cd7 100644 Binary files "a/2\347\255\226\347\225\245\346\250\241\345\274\217/.DS_Store" and "b/2\347\255\226\347\225\245\346\250\241\345\274\217/.DS_Store" differ diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" index c19db37..941e5b5 100644 Binary files "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" and "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" differ diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCaseReturn.h" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCaseReturn.h" index fffbcde..be4ef3e 100644 --- "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCaseReturn.h" +++ "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCaseReturn.h" @@ -9,5 +9,5 @@ #import #import "HCDCashBase.h" @interface HCDCaseReturn : NSObject --(instancetype)initWithMoneyCondition:(CGFloat)moneyCondition moneyReturn:(CGFloat)moneyReturn; +-(instancetype)initWithMoneyReturn:(CGFloat)moneyReturn; @end diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCaseReturn.m" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCaseReturn.m" index 4d4b98a..cee2874 100644 --- "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCaseReturn.m" +++ "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCaseReturn.m" @@ -9,20 +9,21 @@ #import "HCDCaseReturn.h" @interface HCDCaseReturn () -@property(nonatomic)CGFloat moneyCondition; + @property(nonatomic)CGFloat moneyReturn; @end @implementation HCDCaseReturn --(instancetype)initWithMoneyCondition:(CGFloat)moneyCondition moneyReturn:(CGFloat)moneyReturn{ +//@synthesize money = _money; + +-(instancetype)initWithMoneyReturn:(CGFloat)moneyReturn{ self = [super init]; if (self) { - _moneyCondition = moneyCondition; _moneyReturn = moneyReturn; } return self; } -(CGFloat)acceptCash:(CGFloat)cash{ - return self.moneyCondition - self.moneyReturn; + return cash - self.moneyReturn; } @end diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashBase.h" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashBase.h" index 92d7575..d483164 100644 --- "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashBase.h" +++ "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashBase.h" @@ -9,5 +9,6 @@ #import #import @protocol HCDCashBase +//@property(nonatomic,assign)CGFloat money; -(CGFloat)acceptCash:(CGFloat)cash; @end diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashContext.h" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashContext.h" index a2ff907..1054dd5 100644 --- "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashContext.h" +++ "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashContext.h" @@ -8,7 +8,17 @@ #import #import "HCDCashBase.h" + + +typedef NS_ENUM(NSInteger, HCDCashType){ + CashTypeNormal = 0, + CashTypeRobate, + CashTypeReturn +}; + + @interface HCDCashContext : NSObject -(instancetype)initWithCashSuper:(id)cashBase; +-(instancetype)initWithCashType:(HCDCashType)type; -(CGFloat)getResult:(CGFloat)money; @end diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashContext.m" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashContext.m" index a97981d..7ba381b 100644 --- "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashContext.m" +++ "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashContext.m" @@ -7,7 +7,9 @@ // #import "HCDCashContext.h" - +#import "HCDCaseReturn.h" +#import "HCDCashNormal.h" +#import "HCDCashRobate.h" @interface HCDCashContext() @property(strong,nonatomic) id cashSuper; @end @@ -20,6 +22,23 @@ -(instancetype)initWithCashSuper:(id)cashBase{ } return self; } + +-(instancetype)initWithCashType:(HCDCashType)type{ + self = [super init]; + if (self) { + if (type == CashTypeNormal) { + self.cashSuper = [[HCDCashNormal alloc]init]; + // self.cashSuper.money = money; + }else if(type == CashTypeRobate){ + self.cashSuper = [[HCDCashRobate alloc]initWithMoneyRebate:0.8]; + // self.cashSuper.money = money; + }else if(type == CashTypeReturn){ + self.cashSuper = [[HCDCaseReturn alloc]initWithMoneyReturn:5]; + } + } + return self; +} + -(CGFloat)getResult:(CGFloat)money{ return [self.cashSuper acceptCash:money]; } diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashNormal.m" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashNormal.m" index 57145ec..fb5464e 100644 --- "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashNormal.m" +++ "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashNormal.m" @@ -9,6 +9,9 @@ #import "HCDCashNormal.h" @implementation HCDCashNormal + +//@synthesize money = _money; + -(CGFloat)acceptCash:(CGFloat)cash{ return cash; } diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashRobate.m" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashRobate.m" index d6e729b..64a2d0c 100644 --- "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashRobate.m" +++ "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/HCDCashRobate.m" @@ -13,6 +13,7 @@ @interface HCDCashRobate () @end @implementation HCDCashRobate +//@synthesize money = _money; -(instancetype)initWithMoneyRebate:(CGFloat)moneyRebate{ self = [super init]; if (self) { diff --git "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/ViewController.m" "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/ViewController.m" index c9606b9..d7b8ebc 100644 --- "a/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/ViewController.m" +++ "b/2\347\255\226\347\225\245\346\250\241\345\274\217/2\347\255\226\347\225\245\346\250\241\345\274\217/ViewController.m" @@ -20,13 +20,17 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - HCDCashRobate *robate = [[HCDCashRobate alloc]initWithMoneyRebate:0.8]; - HCDCashContext *context = [[HCDCashContext alloc]initWithCashSuper:robate]; + + + HCDCashContext *context = [[HCDCashContext alloc]initWithCashType:CashTypeNormal]; NSLog(@"结果是%f",[context getResult:100]); + + + HCDCashContext *contextReturn = [[HCDCashContext alloc]initWithCashType:CashTypeReturn]; + NSLog(@"结果是%f",[contextReturn getResult:100]); - HCDCaseReturn *cashReturn = [[HCDCaseReturn alloc]initWithMoneyCondition:300 moneyReturn:100]; - HCDCashContext *contextReturn = [[HCDCashContext alloc]initWithCashSuper:cashReturn]; - NSLog(@"结果是%f",[contextReturn getResult:0]); + HCDCashContext *contextRobate = [[HCDCashContext alloc]initWithCashType:CashTypeRobate]; + NSLog(@"结果是%f",[contextRobate getResult:100]); } - (void)didReceiveMemoryWarning { diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/.DS_Store" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/.DS_Store" index 0842eed..d1f221d 100644 Binary files "a/3\350\243\205\351\245\260\346\250\241\345\274\217/.DS_Store" and "b/3\350\243\205\351\245\260\346\250\241\345\274\217/.DS_Store" differ diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/project.pbxproj" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/project.pbxproj" index 60515f4..3d79b63 100644 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/project.pbxproj" +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/project.pbxproj" @@ -7,6 +7,11 @@ objects = { /* Begin PBXBuildFile section */ + 4D1868DA1ED6E27400F8C3C0 /* Component.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1868D91ED6E27400F8C3C0 /* Component.m */; }; + 4D1868DD1ED6E2B200F8C3C0 /* ConcreteComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1868DC1ED6E2B200F8C3C0 /* ConcreteComponent.m */; }; + 4D1868E01ED6E2D500F8C3C0 /* Decorator.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1868DF1ED6E2D500F8C3C0 /* Decorator.m */; }; + 4D1868E31ED6E30900F8C3C0 /* ConcreteDecoratorA.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1868E21ED6E30900F8C3C0 /* ConcreteDecoratorA.m */; }; + 4D1868E61ED6E31400F8C3C0 /* ConcreteDecoratorB.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1868E51ED6E31400F8C3C0 /* ConcreteDecoratorB.m */; }; DD17B1B01B7B058000943EDE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DD17B1AF1B7B058000943EDE /* main.m */; }; DD17B1B31B7B058000943EDE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DD17B1B21B7B058000943EDE /* AppDelegate.m */; }; DD17B1B61B7B058000943EDE /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD17B1B51B7B058000943EDE /* ViewController.m */; }; @@ -14,11 +19,6 @@ DD17B1BB1B7B058000943EDE /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DD17B1BA1B7B058000943EDE /* Images.xcassets */; }; DD17B1BE1B7B058000943EDE /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = DD17B1BC1B7B058000943EDE /* LaunchScreen.xib */; }; DD17B1CA1B7B058000943EDE /* _____Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD17B1C91B7B058000943EDE /* _____Tests.m */; }; - DD17B1D61B7B0D5700943EDE /* HCDstractCellPhone.m in Sources */ = {isa = PBXBuildFile; fileRef = DD17B1D51B7B0D5700943EDE /* HCDstractCellPhone.m */; }; - DD17B1D91B7B0DDE00943EDE /* HCDnokiaPhone.m in Sources */ = {isa = PBXBuildFile; fileRef = DD17B1D81B7B0DDE00943EDE /* HCDnokiaPhone.m */; }; - DD17B1DC1B7B0E6000943EDE /* HCDdecorator.m in Sources */ = {isa = PBXBuildFile; fileRef = DD17B1DB1B7B0E6000943EDE /* HCDdecorator.m */; }; - DD17B1DF1B7B0F6B00943EDE /* HCDdecoratorGPS.m in Sources */ = {isa = PBXBuildFile; fileRef = DD17B1DE1B7B0F6B00943EDE /* HCDdecoratorGPS.m */; }; - DD17B1E21B7B101C00943EDE /* HCDdecoratorBluetooth.m in Sources */ = {isa = PBXBuildFile; fileRef = DD17B1E11B7B101C00943EDE /* HCDdecoratorBluetooth.m */; }; DD17B1E41B7B11CE00943EDE /* 装饰模式图片.jpg in Resources */ = {isa = PBXBuildFile; fileRef = DD17B1E31B7B11CE00943EDE /* 装饰模式图片.jpg */; }; /* End PBXBuildFile section */ @@ -33,6 +33,16 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 4D1868D81ED6E27400F8C3C0 /* Component.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Component.h; sourceTree = ""; }; + 4D1868D91ED6E27400F8C3C0 /* Component.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Component.m; sourceTree = ""; }; + 4D1868DB1ED6E2B200F8C3C0 /* ConcreteComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcreteComponent.h; sourceTree = ""; }; + 4D1868DC1ED6E2B200F8C3C0 /* ConcreteComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcreteComponent.m; sourceTree = ""; }; + 4D1868DE1ED6E2D500F8C3C0 /* Decorator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Decorator.h; sourceTree = ""; }; + 4D1868DF1ED6E2D500F8C3C0 /* Decorator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Decorator.m; sourceTree = ""; }; + 4D1868E11ED6E30900F8C3C0 /* ConcreteDecoratorA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcreteDecoratorA.h; sourceTree = ""; }; + 4D1868E21ED6E30900F8C3C0 /* ConcreteDecoratorA.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcreteDecoratorA.m; sourceTree = ""; }; + 4D1868E41ED6E31400F8C3C0 /* ConcreteDecoratorB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcreteDecoratorB.h; sourceTree = ""; }; + 4D1868E51ED6E31400F8C3C0 /* ConcreteDecoratorB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcreteDecoratorB.m; sourceTree = ""; }; DD17B1AA1B7B058000943EDE /* 3装饰模式.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "3装饰模式.app"; sourceTree = BUILT_PRODUCTS_DIR; }; DD17B1AE1B7B058000943EDE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DD17B1AF1B7B058000943EDE /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -46,16 +56,6 @@ DD17B1C31B7B058000943EDE /* 3装饰模式Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "3装饰模式Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; DD17B1C81B7B058000943EDE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DD17B1C91B7B058000943EDE /* _____Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "_____Tests.m"; sourceTree = ""; }; - DD17B1D41B7B0D5700943EDE /* HCDstractCellPhone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDstractCellPhone.h; sourceTree = ""; }; - DD17B1D51B7B0D5700943EDE /* HCDstractCellPhone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDstractCellPhone.m; sourceTree = ""; }; - DD17B1D71B7B0DDE00943EDE /* HCDnokiaPhone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDnokiaPhone.h; sourceTree = ""; }; - DD17B1D81B7B0DDE00943EDE /* HCDnokiaPhone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDnokiaPhone.m; sourceTree = ""; }; - DD17B1DA1B7B0E6000943EDE /* HCDdecorator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDdecorator.h; sourceTree = ""; }; - DD17B1DB1B7B0E6000943EDE /* HCDdecorator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDdecorator.m; sourceTree = ""; }; - DD17B1DD1B7B0F6B00943EDE /* HCDdecoratorGPS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDdecoratorGPS.h; sourceTree = ""; }; - DD17B1DE1B7B0F6B00943EDE /* HCDdecoratorGPS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDdecoratorGPS.m; sourceTree = ""; }; - DD17B1E01B7B101C00943EDE /* HCDdecoratorBluetooth.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDdecoratorBluetooth.h; sourceTree = ""; }; - DD17B1E11B7B101C00943EDE /* HCDdecoratorBluetooth.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDdecoratorBluetooth.m; sourceTree = ""; }; DD17B1E31B7B11CE00943EDE /* 装饰模式图片.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "装饰模式图片.jpg"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -77,6 +77,30 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4D1868D61ED6E22400F8C3C0 /* component */ = { + isa = PBXGroup; + children = ( + 4D1868D81ED6E27400F8C3C0 /* Component.h */, + 4D1868D91ED6E27400F8C3C0 /* Component.m */, + 4D1868DB1ED6E2B200F8C3C0 /* ConcreteComponent.h */, + 4D1868DC1ED6E2B200F8C3C0 /* ConcreteComponent.m */, + ); + name = component; + sourceTree = ""; + }; + 4D1868D71ED6E23000F8C3C0 /* decorator */ = { + isa = PBXGroup; + children = ( + 4D1868DE1ED6E2D500F8C3C0 /* Decorator.h */, + 4D1868DF1ED6E2D500F8C3C0 /* Decorator.m */, + 4D1868E11ED6E30900F8C3C0 /* ConcreteDecoratorA.h */, + 4D1868E21ED6E30900F8C3C0 /* ConcreteDecoratorA.m */, + 4D1868E41ED6E31400F8C3C0 /* ConcreteDecoratorB.h */, + 4D1868E51ED6E31400F8C3C0 /* ConcreteDecoratorB.m */, + ); + name = decorator; + sourceTree = ""; + }; DD17B1A11B7B058000943EDE = { isa = PBXGroup; children = ( @@ -98,7 +122,7 @@ DD17B1AC1B7B058000943EDE /* 3装饰模式 */ = { isa = PBXGroup; children = ( - DD17B1D31B7B058800943EDE /* decorate */, + DD17B1D31B7B058800943EDE /* 装饰模式 */, DD17B1B11B7B058000943EDE /* AppDelegate.h */, DD17B1B21B7B058000943EDE /* AppDelegate.m */, DD17B1B41B7B058000943EDE /* ViewController.h */, @@ -137,22 +161,14 @@ name = "Supporting Files"; sourceTree = ""; }; - DD17B1D31B7B058800943EDE /* decorate */ = { + DD17B1D31B7B058800943EDE /* 装饰模式 */ = { isa = PBXGroup; children = ( + 4D1868D71ED6E23000F8C3C0 /* decorator */, + 4D1868D61ED6E22400F8C3C0 /* component */, DD17B1E31B7B11CE00943EDE /* 装饰模式图片.jpg */, - DD17B1D41B7B0D5700943EDE /* HCDstractCellPhone.h */, - DD17B1D51B7B0D5700943EDE /* HCDstractCellPhone.m */, - DD17B1D71B7B0DDE00943EDE /* HCDnokiaPhone.h */, - DD17B1D81B7B0DDE00943EDE /* HCDnokiaPhone.m */, - DD17B1DA1B7B0E6000943EDE /* HCDdecorator.h */, - DD17B1DB1B7B0E6000943EDE /* HCDdecorator.m */, - DD17B1DD1B7B0F6B00943EDE /* HCDdecoratorGPS.h */, - DD17B1DE1B7B0F6B00943EDE /* HCDdecoratorGPS.m */, - DD17B1E01B7B101C00943EDE /* HCDdecoratorBluetooth.h */, - DD17B1E11B7B101C00943EDE /* HCDdecoratorBluetooth.m */, ); - name = decorate; + name = "装饰模式"; sourceTree = ""; }; /* End PBXGroup section */ @@ -256,14 +272,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - DD17B1D91B7B0DDE00943EDE /* HCDnokiaPhone.m in Sources */, DD17B1B61B7B058000943EDE /* ViewController.m in Sources */, - DD17B1E21B7B101C00943EDE /* HCDdecoratorBluetooth.m in Sources */, - DD17B1DF1B7B0F6B00943EDE /* HCDdecoratorGPS.m in Sources */, - DD17B1D61B7B0D5700943EDE /* HCDstractCellPhone.m in Sources */, + 4D1868DA1ED6E27400F8C3C0 /* Component.m in Sources */, DD17B1B31B7B058000943EDE /* AppDelegate.m in Sources */, + 4D1868E31ED6E30900F8C3C0 /* ConcreteDecoratorA.m in Sources */, + 4D1868DD1ED6E2B200F8C3C0 /* ConcreteComponent.m in Sources */, DD17B1B01B7B058000943EDE /* main.m in Sources */, - DD17B1DC1B7B0E6000943EDE /* HCDdecorator.m in Sources */, + 4D1868E01ED6E2D500F8C3C0 /* Decorator.m in Sources */, + 4D1868E61ED6E31400F8C3C0 /* ConcreteDecoratorB.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -458,6 +474,7 @@ DD17B1CF1B7B058000943EDE /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; DD17B1D01B7B058000943EDE /* Build configuration list for PBXNativeTarget "3装饰模式Tests" */ = { isa = XCConfigurationList; @@ -466,6 +483,7 @@ DD17B1D21B7B058000943EDE /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/3\350\243\205\351\245\260\346\250\241\345\274\217.xcscheme" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/3\350\243\205\351\245\260\346\250\241\345\274\217.xcscheme" new file mode 100644 index 0000000..847c279 --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/3\350\243\205\351\245\260\346\250\241\345\274\217.xcscheme" @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/xcschememanagement.plist" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/xcschememanagement.plist" new file mode 100644 index 0000000..7e54617 --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217.xcodeproj/xcuserdata/huangchengdu.xcuserdatad/xcschemes/xcschememanagement.plist" @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + 3装饰模式.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + DD17B1A91B7B058000943EDE + + primary + + + DD17B1C21B7B058000943EDE + + primary + + + + + diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Component.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Component.h" new file mode 100644 index 0000000..e8d2465 --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Component.h" @@ -0,0 +1,14 @@ +// +// Component.h +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import + +@interface Component : NSObject + +-(void)operation; +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Component.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Component.m" new file mode 100644 index 0000000..30b265c --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Component.m" @@ -0,0 +1,16 @@ +// +// Component.m +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Component.h" + +@implementation Component + +- (void)operation{ + +} +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteComponent.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteComponent.h" new file mode 100644 index 0000000..a962955 --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteComponent.h" @@ -0,0 +1,13 @@ +// +// ConcreteComponent.h +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Component.h" + +@interface ConcreteComponent : Component + +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteComponent.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteComponent.m" new file mode 100644 index 0000000..b0a5ad2 --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteComponent.m" @@ -0,0 +1,17 @@ +// +// ConcreteComponent.m +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "ConcreteComponent.h" + +@implementation ConcreteComponent + +- (void)operation{ + NSLog(@"ConcreteComponent具体对象的操作,装饰之前"); +} + +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorA.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorA.h" new file mode 100644 index 0000000..25430f5 --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorA.h" @@ -0,0 +1,14 @@ +// +// ConcreteDecoratorA.h +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Decorator.h" + +@interface ConcreteDecoratorA : Decorator +//本类独有属性,区别于ConcreteDecoratorB这个装饰者 +@property(nonatomic, copy)NSString *addedState; +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorA.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorA.m" new file mode 100644 index 0000000..b281f5a --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorA.m" @@ -0,0 +1,18 @@ +// +// ConcreteDecoratorA.m +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "ConcreteDecoratorA.h" + +@implementation ConcreteDecoratorA + +-(void)operation{ + [super operation]; + self.addedState = @"New State"; + NSLog(@"ConcreteDecoratorA添加的装饰功能,相当于对Component进行装饰"); +} +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorB.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorB.h" new file mode 100644 index 0000000..1bfd2b0 --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorB.h" @@ -0,0 +1,13 @@ +// +// ConcreteDecoratorB.h +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Decorator.h" + +@interface ConcreteDecoratorB : Decorator + +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorB.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorB.m" new file mode 100644 index 0000000..49cf67f --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ConcreteDecoratorB.m" @@ -0,0 +1,21 @@ +// +// ConcreteDecoratorB.m +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "ConcreteDecoratorB.h" + +@implementation ConcreteDecoratorB + +- (void)operation{ + [super operation]; + [self addedBehavior]; +} + +- (void)addedBehavior{ + NSLog(@"ConcreteDecoratorB添加的装饰功能,相当于对Component进行装饰"); +} +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Decorator.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Decorator.h" new file mode 100644 index 0000000..3e77fae --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Decorator.h" @@ -0,0 +1,14 @@ +// +// Decorator.h +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Component.h" + +@interface Decorator : Component +//装饰对象需要装饰的原始对象 +@property(nonatomic, strong)Component *component; +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Decorator.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Decorator.m" new file mode 100644 index 0000000..b9b6b90 --- /dev/null +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/Decorator.m" @@ -0,0 +1,19 @@ +// +// Decorator.m +// 3装饰模式 +// +// Created by huangchengdu on 17/5/25. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "Decorator.h" + +@implementation Decorator + +-(void)operation{ + if (self.component) { + [self.component operation]; + } +} + +@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecorator.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecorator.h" deleted file mode 100644 index ce16970..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecorator.h" +++ /dev/null @@ -1,14 +0,0 @@ -// -// HCDdecorator.h -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDstractCellPhone.h" - -@interface HCDdecorator : HCDstractCellPhone -@property(nonatomic,strong) HCDstractCellPhone *abstractCellPhone; -- (void)setComponents:(HCDstractCellPhone *)component; -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecorator.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecorator.m" deleted file mode 100644 index 73f803d..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecorator.m" +++ /dev/null @@ -1,21 +0,0 @@ -// -// HCDdecorator.m -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDdecorator.h" - -@implementation HCDdecorator --(void)setComponents:(HCDstractCellPhone *)component{ - self.abstractCellPhone = component; -} --(NSString *)callNumber{ - return [self.abstractCellPhone callNumber]; -} --(NSString *)sendMessage{ - return self.abstractCellPhone.sendMessage; -} -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorBluetooth.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorBluetooth.h" deleted file mode 100644 index bc848bb..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorBluetooth.h" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDdecoratorBluetooth.h -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDdecorator.h" - -@interface HCDdecoratorBluetooth : HCDdecorator - -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorBluetooth.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorBluetooth.m" deleted file mode 100644 index 9deff17..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorBluetooth.m" +++ /dev/null @@ -1,21 +0,0 @@ -// -// HCDdecoratorBluetooth.m -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDdecoratorBluetooth.h" - -@implementation HCDdecoratorBluetooth -- (NSString *)callNumber -{ - return [NSString stringWithFormat:@"%@ with bluetooth", [super callNumber]]; -} - -- (NSString *)sendMessage -{ - return [NSString stringWithFormat:@"%@ with bluetooth", [super sendMessage]]; -} -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorGPS.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorGPS.h" deleted file mode 100644 index 684e9f9..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorGPS.h" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDdecoratorGPS.h -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDdecorator.h" - -@interface HCDdecoratorGPS : HCDdecorator - -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorGPS.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorGPS.m" deleted file mode 100644 index 8c810a7..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDdecoratorGPS.m" +++ /dev/null @@ -1,22 +0,0 @@ -// -// HCDdecoratorGPS.m -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDdecoratorGPS.h" - -@implementation HCDdecoratorGPS -- (NSString *)callNumber -{ - return [NSString stringWithFormat:@"%@ with GPS", [super callNumber]]; -} - -- (NSString *)sendMessage -{ - return [NSString stringWithFormat:@"%@ with GPS", [super sendMessage]]; -} - -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDnokiaPhone.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDnokiaPhone.h" deleted file mode 100644 index 7dd8fe6..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDnokiaPhone.h" +++ /dev/null @@ -1,13 +0,0 @@ -// -// HCDnokiaPhone.h -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDstractCellPhone.h" - -@interface HCDnokiaPhone : HCDstractCellPhone - -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDnokiaPhone.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDnokiaPhone.m" deleted file mode 100644 index bdc7668..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDnokiaPhone.m" +++ /dev/null @@ -1,18 +0,0 @@ -// -// HCDnokiaPhone.m -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDnokiaPhone.h" - -@implementation HCDnokiaPhone -- (NSString *)callNumber{ - return @"Nokiaphone call somebody"; -} --(NSString *)sendMessage{ - return @"NokiaPhone send message to somebody"; -} -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDstractCellPhone.h" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDstractCellPhone.h" deleted file mode 100644 index fcd9404..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDstractCellPhone.h" +++ /dev/null @@ -1,14 +0,0 @@ -// -// HCDstractCellPhone.h -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import - -@interface HCDstractCellPhone : NSObject -- (NSString *)callNumber; -- (NSString *)sendMessage; -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDstractCellPhone.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDstractCellPhone.m" deleted file mode 100644 index 2968f91..0000000 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/HCDstractCellPhone.m" +++ /dev/null @@ -1,18 +0,0 @@ -// -// HCDstractCellPhone.m -// 3装饰模式 -// -// Created by yifan on 15/8/12. -// Copyright (c) 2015年 黄成都. All rights reserved. -// - -#import "HCDstractCellPhone.h" - -@implementation HCDstractCellPhone --(NSString *)callNumber{ - return @"phone call someBody"; -} --(NSString *)sendMessage{ - return @"phone send a message to somebody"; -} -@end diff --git "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ViewController.m" "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ViewController.m" index 17d0439..367d728 100644 --- "a/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ViewController.m" +++ "b/3\350\243\205\351\245\260\346\250\241\345\274\217/3\350\243\205\351\245\260\346\250\241\345\274\217/ViewController.m" @@ -7,10 +7,10 @@ // #import "ViewController.h" -#import "HCDstractCellPhone.h" -#import "HCDnokiaPhone.h" -#import "HCDdecoratorGPS.h" -#import "HCDdecoratorBluetooth.h" +#import "ConcreteDecoratorA.h" +#import "ConcreteDecoratorB.h" +#import "ConcreteComponent.h" + @interface ViewController () @end @@ -19,35 +19,20 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; + //原始对象 + ConcreteComponent *component = [[ConcreteComponent alloc]init]; + //装饰对象 + ConcreteDecoratorA *decoratorA = [[ConcreteDecoratorA alloc]init]; + ConcreteDecoratorB *decoratorB = [[ConcreteDecoratorB alloc]init]; - /* - 说明: - HCDstractCellPhone对应图片中的Component - HCDnokiaPhone对应图片中的ConcreteComponent - HCDdecorator对应图片中的Decorator - HCDdecoratorGPS对应图片中的ConcreteDecoratorA - HCDdecoratorBluetooth对应图片中的ConcreteDecoratorB - */ - //核心思想就是通过HCDdecorator各种子类来为HCDnokiaPhone添加各种功能。而不需要改变HCDnokiaPhone。 - //参考地址:http://www.tuicool.com/articles/jyeU3mu - HCDstractCellPhone *phone = [[HCDnokiaPhone alloc]init]; - NSLog(@"%@",phone.callNumber); - NSLog(@"%@",phone.sendMessage); + //装饰对象指定原始对象,后面就是用装饰对象。这样既有原始对象的功能,也有装饰对象的功能。 + decoratorA.component = component; + decoratorB.component = component; - HCDdecoratorGPS *GPS = [[HCDdecoratorGPS alloc]init]; - [GPS setComponents:phone]; - NSLog(@"%@",GPS.callNumber); - NSLog(@"%@",GPS.sendMessage); + [decoratorA operation]; + [decoratorB operation]; - HCDdecoratorBluetooth *bluetooth = [[HCDdecoratorBluetooth alloc] init]; - [bluetooth setComponents:phone]; - NSLog(@"%@",bluetooth.callNumber); - NSLog(@"%@",bluetooth.sendMessage); } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} @end diff --git "a/4\344\273\243\347\220\206\346\250\241\345\274\217/4\344\273\243\347\220\206\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcshareddata/4\344\273\243\347\220\206\346\250\241\345\274\217.xccheckout" "b/4\344\273\243\347\220\206\346\250\241\345\274\217/4\344\273\243\347\220\206\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcshareddata/4\344\273\243\347\220\206\346\250\241\345\274\217.xccheckout" index b362a49..8bea7a4 100644 --- "a/4\344\273\243\347\220\206\346\250\241\345\274\217/4\344\273\243\347\220\206\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcshareddata/4\344\273\243\347\220\206\346\250\241\345\274\217.xccheckout" +++ "b/4\344\273\243\347\220\206\346\250\241\345\274\217/4\344\273\243\347\220\206\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcshareddata/4\344\273\243\347\220\206\346\250\241\345\274\217.xccheckout" @@ -7,14 +7,14 @@ IDESourceControlProjectIdentifier E37839D8-7944-4609-8C54-7A10E7D5FF09 IDESourceControlProjectName - project + 4代理模式 IDESourceControlProjectOriginsDictionary 97B4AD1D63A96A3E6D01F6FF529543E2092CC1C1 https://github.com/huang303513/Design-Pattern-For-iOS.git IDESourceControlProjectPath - 4代理模式/4代理模式.xcodeproj/project.xcworkspace + 4代理模式/4代理模式.xcodeproj IDESourceControlProjectRelativeInstallPathDictionary 97B4AD1D63A96A3E6D01F6FF529543E2092CC1C1 diff --git "a/4\344\273\243\347\220\206\346\250\241\345\274\217/4\344\273\243\347\220\206\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" "b/4\344\273\243\347\220\206\346\250\241\345\274\217/4\344\273\243\347\220\206\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" index 600d3e0..55bb69a 100644 Binary files "a/4\344\273\243\347\220\206\346\250\241\345\274\217/4\344\273\243\347\220\206\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" and "b/4\344\273\243\347\220\206\346\250\241\345\274\217/4\344\273\243\347\220\206\346\250\241\345\274\217.xcodeproj/project.xcworkspace/xcuserdata/yifan.xcuserdatad/UserInterfaceState.xcuserstate" differ 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 4d04662..e9e5e38 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,10 @@ objects = { /* Begin PBXBuildFile section */ + 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 */; }; + 4DC94DA21ECC6ACA00A8DB96 /* HCDArm.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DC94DA11ECC6ACA00A8DB96 /* HCDArm.m */; }; DD4F86B71B7C38C600A32343 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4F86B61B7C38C600A32343 /* main.m */; }; DD4F86BA1B7C38C600A32343 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4F86B91B7C38C600A32343 /* AppDelegate.m */; }; DD4F86BD1B7C38C600A32343 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4F86BC1B7C38C600A32343 /* ViewController.m */; }; @@ -30,6 +34,14 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 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 = ""; }; + 4DC94D9B1ECC6A9700A8DB96 /* HCDBody.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDBody.m; sourceTree = ""; }; + 4DC94D9D1ECC6AA600A8DB96 /* HCDLeg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDLeg.h; sourceTree = ""; }; + 4DC94D9E1ECC6AA600A8DB96 /* HCDLeg.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDLeg.m; sourceTree = ""; }; + 4DC94DA01ECC6ACA00A8DB96 /* HCDArm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCDArm.h; sourceTree = ""; }; + 4DC94DA11ECC6ACA00A8DB96 /* HCDArm.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCDArm.m; sourceTree = ""; }; DD4F86B11B7C38C600A32343 /* 8建造者模式.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "8建造者模式.app"; sourceTree = BUILT_PRODUCTS_DIR; }; DD4F86B51B7C38C600A32343 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DD4F86B61B7C38C600A32343 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -70,6 +82,42 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4DC94D961ECC6A5E00A8DB96 /* 工具类 */ = { + isa = PBXGroup; + children = ( + 4DC94D971ECC6A8500A8DB96 /* HCDHeader.h */, + 4DC94D981ECC6A8500A8DB96 /* HCDHeader.m */, + 4DC94D9A1ECC6A9700A8DB96 /* HCDBody.h */, + 4DC94D9B1ECC6A9700A8DB96 /* HCDBody.m */, + 4DC94D9D1ECC6AA600A8DB96 /* HCDLeg.h */, + 4DC94D9E1ECC6AA600A8DB96 /* HCDLeg.m */, + 4DC94DA01ECC6ACA00A8DB96 /* HCDArm.h */, + 4DC94DA11ECC6ACA00A8DB96 /* HCDArm.m */, + ); + name = "工具类"; + sourceTree = ""; + }; + 4DC94DA31ECC6D1E00A8DB96 /* Director */ = { + isa = PBXGroup; + children = ( + DD4F86E21B7C49E600A32343 /* HCDPersonBuilderDirector.h */, + DD4F86E31B7C49E600A32343 /* HCDPersonBuilderDirector.m */, + ); + name = Director; + sourceTree = ""; + }; + 4DC94DA41ECC6D2600A8DB96 /* Builder */ = { + isa = PBXGroup; + children = ( + DD4F86DB1B7C48ED00A32343 /* HCDPresionBuilder.h */, + DD4F86DC1B7C497400A32343 /* HCDPersonThinBuilder.h */, + DD4F86DD1B7C497400A32343 /* HCDPersonThinBuilder.m */, + DD4F86DF1B7C49BD00A32343 /* HCDPersonFatBuilder.h */, + DD4F86E01B7C49BD00A32343 /* HCDPersonFatBuilder.m */, + ); + name = Builder; + sourceTree = ""; + }; DD4F86A81B7C38C600A32343 = { isa = PBXGroup; children = ( @@ -133,13 +181,9 @@ DD4F86DA1B7C48C000A32343 /* 建造者模式 */ = { isa = PBXGroup; children = ( - DD4F86DB1B7C48ED00A32343 /* HCDPresionBuilder.h */, - DD4F86DC1B7C497400A32343 /* HCDPersonThinBuilder.h */, - DD4F86DD1B7C497400A32343 /* HCDPersonThinBuilder.m */, - DD4F86DF1B7C49BD00A32343 /* HCDPersonFatBuilder.h */, - DD4F86E01B7C49BD00A32343 /* HCDPersonFatBuilder.m */, - DD4F86E21B7C49E600A32343 /* HCDPersonBuilderDirector.h */, - DD4F86E31B7C49E600A32343 /* HCDPersonBuilderDirector.m */, + 4DC94DA41ECC6D2600A8DB96 /* Builder */, + 4DC94DA31ECC6D1E00A8DB96 /* Director */, + 4DC94D961ECC6A5E00A8DB96 /* 工具类 */, ); name = "建造者模式"; sourceTree = ""; @@ -244,7 +288,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4DC94D9F1ECC6AA600A8DB96 /* HCDLeg.m in Sources */, DD4F86E41B7C49E600A32343 /* HCDPersonBuilderDirector.m in Sources */, + 4DC94DA21ECC6ACA00A8DB96 /* HCDArm.m in Sources */, + 4DC94D9C1ECC6A9700A8DB96 /* HCDBody.m in Sources */, + 4DC94D991ECC6A8500A8DB96 /* HCDHeader.m in Sources */, DD4F86BD1B7C38C600A32343 /* ViewController.m in Sources */, DD4F86DE1B7C497400A32343 /* HCDPersonThinBuilder.m in Sources */, DD4F86BA1B7C38C600A32343 /* AppDelegate.m in Sources */, @@ -444,6 +492,7 @@ DD4F86D61B7C38C600A32343 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; DD4F86D71B7C38C600A32343 /* Build configuration list for PBXNativeTarget "8建造者模式Tests" */ = { isa = XCConfigurationList; @@ -452,6 +501,7 @@ DD4F86D91B7C38C600A32343 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; 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/Base.lproj/Main.storyboard" "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/Base.lproj/Main.storyboard" index d912f9d..81b9c84 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/Base.lproj/Main.storyboard" +++ "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/Base.lproj/Main.storyboard" @@ -1,25 +1,49 @@ - + + + + - + + + - + - + - + + + + + + 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/HCDArm.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/HCDArm.h" new file mode 100644 index 0000000..1e1ca6c --- /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/HCDArm.h" @@ -0,0 +1,15 @@ +// +// HCDArm.h +// 8建造者模式 +// +// Created by huangchengdu on 17/5/17. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import + +@interface HCDArm : NSObject + +-(void)work; + +@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/HCDArm.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/HCDArm.m" new file mode 100644 index 0000000..d6b370e --- /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/HCDArm.m" @@ -0,0 +1,17 @@ +// +// HCDArm.m +// 8建造者模式 +// +// Created by huangchengdu on 17/5/17. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "HCDArm.h" + +@implementation HCDArm + +-(void)work{ + NSLog(@"成功构建了手臂------HCDArm"); +} + +@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/HCDBody.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/HCDBody.h" new file mode 100644 index 0000000..1bb73c4 --- /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/HCDBody.h" @@ -0,0 +1,15 @@ +// +// HCDBody.h +// 8建造者模式 +// +// Created by huangchengdu on 17/5/17. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import + +@interface HCDBody : NSObject + +-(void)work; + +@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/HCDBody.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/HCDBody.m" new file mode 100644 index 0000000..d7646b9 --- /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/HCDBody.m" @@ -0,0 +1,17 @@ +// +// HCDBody.m +// 8建造者模式 +// +// Created by huangchengdu on 17/5/17. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "HCDBody.h" + +@implementation HCDBody + +-(void)work{ + NSLog(@"成功构建了身体-----HCDBody"); +} + +@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/HCDHeader.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/HCDHeader.h" new file mode 100644 index 0000000..bcfa5b1 --- /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/HCDHeader.h" @@ -0,0 +1,15 @@ +// +// HCDHeader.h +// 8建造者模式 +// +// Created by huangchengdu on 17/5/17. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import + +@interface HCDHeader : NSObject + +-(void)work; + +@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/HCDHeader.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/HCDHeader.m" new file mode 100644 index 0000000..e9357e9 --- /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/HCDHeader.m" @@ -0,0 +1,17 @@ +// +// HCDHeader.m +// 8建造者模式 +// +// Created by huangchengdu on 17/5/17. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "HCDHeader.h" + +@implementation HCDHeader + +-(void)work{ + NSLog(@"成功构建了头-----HCDHead"); +} + +@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/HCDLeg.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/HCDLeg.h" new file mode 100644 index 0000000..15a60d2 --- /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/HCDLeg.h" @@ -0,0 +1,15 @@ +// +// HCDLeg.h +// 8建造者模式 +// +// Created by huangchengdu on 17/5/17. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import + +@interface HCDLeg : NSObject + +-(void)work; + +@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/HCDLeg.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/HCDLeg.m" new file mode 100644 index 0000000..cb7239b --- /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/HCDLeg.m" @@ -0,0 +1,17 @@ +// +// HCDLeg.m +// 8建造者模式 +// +// Created by huangchengdu on 17/5/17. +// Copyright © 2017年 黄成都. All rights reserved. +// + +#import "HCDLeg.h" + +@implementation HCDLeg + +-(void)work{ + NSLog(@"成功构建了腿------HCDLeg"); +} + +@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 218f220..8c251d8 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" @@ -8,7 +8,12 @@ #import #import "HCDPresionBuilder.h" + @interface HCDPersonBuilderDirector : NSObject --(instancetype)initWithPersonBuilder:(id)builder; + + +@property(nonatomic, strong)HCDPresionBuilder builder; + -(void)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/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 6f472da..d47aa64 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" @@ -7,25 +7,20 @@ // #import "HCDPersonBuilderDirector.h" +#import "HCDPersonFatBuilder.h" +#import "HCDPersonThinBuilder.h" + @interface HCDPersonBuilderDirector () -@property(nonatomic,strong)id builder; + @end @implementation HCDPersonBuilderDirector --(instancetype)initWithPersonBuilder:(id)builder{ - self = [super init]; - if (self) { - _builder = builder; - } - return self; -} + + -(void)buildPerson{ - [self.builder buildHead]; - [self.builder buildBody]; - [self.builder buildArmLeft]; - [self.builder buildArmRight]; - [self.builder buildLegLeft]; - [self.builder buildLegRight]; + NSLog(@"===============director指挥builder开始建造===================="); + [self.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 197d136..03c5717 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" @@ -8,6 +8,7 @@ #import #import "HCDPresionBuilder.h" + @interface HCDPersonFatBuilder : NSObject @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 60f0230..dc8d3d4 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" @@ -7,29 +7,67 @@ // #import "HCDPersonFatBuilder.h" +#import "HCDHeader.h" +#import "HCDBody.h" +#import "HCDLeg.h" +#import "HCDArm.h" + +@interface HCDPersonFatBuilder() +@property(nonatomic, strong)HCDHeader *header; +@property(nonatomic, strong)HCDBody *body; +@property(nonatomic, strong)HCDLeg *leg; +@property(nonatomic, strong)HCDArm *arm; +@end @implementation HCDPersonFatBuilder + +-(instancetype)init{ + self = [super init]; + if (self) { + _header = [[HCDHeader alloc]init]; + _body = [[HCDBody alloc]init]; + _leg = [[HCDLeg alloc]init]; + _arm = [[HCDArm alloc]init]; + } + return self; +} + +-(void)buildPerson{ + [self buildHead]; + [self buildBody]; + [self buildArmLeft]; + [self buildArmRight]; + [self buildLegLeft]; + [self buildLegRight]; +} + - (void)buildHead { NSLog(@"建造胖子的头部"); + [self.header work]; } - (void)buildBody { NSLog(@"建造胖子的身体"); + [self.body work]; } - (void)buildArmLeft { NSLog(@"建造胖子的左手"); + [self.arm work]; } - (void)buildArmRight { NSLog(@"建造胖子的右手"); + [self.arm work]; } - (void)buildLegLeft { NSLog(@"建造胖子的左脚"); + [self.leg work]; } - (void)buildLegRight { NSLog(@"建造胖子的右脚"); + [self.leg work]; } @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 21d269e..ada8e39 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" @@ -7,30 +7,71 @@ // #import "HCDPersonThinBuilder.h" +#import "HCDHeader.h" +#import "HCDBody.h" +#import "HCDLeg.h" +#import "HCDArm.h" + + +@interface HCDPersonThinBuilder() +@property(nonatomic, strong)HCDHeader *header; +@property(nonatomic, strong)HCDBody *body; +@property(nonatomic, strong)HCDLeg *leg; +@property(nonatomic, strong)HCDArm *arm; +@end @implementation HCDPersonThinBuilder + + +-(instancetype)init{ + self = [super init]; + if (self) { + _header = [[HCDHeader alloc]init]; + _body = [[HCDBody alloc]init]; + _leg = [[HCDLeg alloc]init]; + _arm = [[HCDArm alloc]init]; + } + return self; +} + +-(void)buildPerson{ + [self buildHead]; + [self buildBody]; + [self buildArmLeft]; + [self buildArmRight]; + [self buildLegLeft]; + [self buildLegRight]; +} + - (void)buildHead { NSLog(@"建造瘦子的头部"); + [self.header work]; } - (void)buildBody { NSLog(@"建造瘦子的身体"); + [self.body work]; } - (void)buildArmLeft { NSLog(@"建造瘦子的左手"); + [self.arm work]; } - (void)buildArmRight { NSLog(@"建造瘦子的右手"); + [self.arm work]; } - (void)buildLegLeft { NSLog(@"建造瘦子的左脚"); + [self.leg work]; } - (void)buildLegRight { NSLog(@"建造瘦子的右脚"); + [self.leg work]; } + @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/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" index 6a28ef2..03c4587 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/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" @@ -8,11 +8,24 @@ #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/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 c229020..c44cd22 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,9 +10,8 @@ #import "HCDPersonBuilderDirector.h" #import "HCDPersonFatBuilder.h" #import "HCDPersonThinBuilder.h" -#import "HCDPresionBuilder.h" -typedef id HCDPresionBuilder; + @interface ViewController () @@ -22,11 +21,25 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - +} + +- (IBAction)buildFat:(id)sender { + HCDPersonBuilderDirector *director = [[HCDPersonBuilderDirector alloc]init]; HCDPresionBuilder builder = [[HCDPersonFatBuilder alloc]init]; - HCDPersonBuilderDirector *fatDirector = [[HCDPersonBuilderDirector alloc]initWithPersonBuilder:builder]; - [fatDirector buildPerson]; - + //为director指定builder + director.builder = builder; + //director发出构建的指令,builder负责具体的建造过程 + [director buildPerson]; +} + +- (IBAction)buildThin:(id)sender { + HCDPersonBuilderDirector *director = [[HCDPersonBuilderDirector alloc]init]; + HCDPresionBuilder builder = [[HCDPersonThinBuilder alloc]init]; + //为director指定builder + director.builder = builder; + //director发出构建的指令,builder负责具体的建造过程 + [director buildPerson]; } + @end diff --git a/README.md b/README.md index 355c14b..9f28329 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,407 @@ -# Design-Pattern-For-iOS -IOS设计模式探索 - -常用的 23 种设计模式 - -不管是 .NET 中的 C# 语言,还是 Java、VB.NET、C++ 或 Objective-C 语言,面向对象语言在设计模式的层面上都是相通的,只不过在设计模式的具体实现上语法稍有差异罢了: - - 策略模式(Strategy),它定义了算法家族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户。 - 装饰模式(Decorator),动态地给一个对象添加一些额外的职责,就增加功能来说,装饰模式比生成子类更为灵活。 - 代理模式(Proxy),为其他对象提供一种代理以控制对这个对象的访问。 - 工厂方法模式(Factory Method),定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使一个类的实例化延迟到其子类。 - 原型模式(Prototype),用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。 - 模板方法模式(Template Method),定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。 - 外观模式(Facade),为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。 - 建造者模式(Builder),将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。 - 观察者模式(Observer),定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态发生变化时,会通知所有观察者对象,使它们能够自动更新自己。 - 抽象工厂模式(Abstract Factory),提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。 - 状态模式(State),当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类。 - 适配器模式(Adapter),将一个类的接口转换成客户希望的另外一个接口。Adapter 模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。 - 备忘录模式(Memento),在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。这样以后就可将该对象恢复到原先保存的状态。 - 组合模式(Composite),将对象组合成树形结构以表示‘部分-整体’的层次结构。组合模式使得用户对单个对象和组合对象的使用具有一致性。 - 迭代器模式(Iterator),提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该对象的内部表示。 - 单例模式(Singleton),保证一个类仅有一个实例,并提供一个访问它的全局访问点。 - 桥接模式(Bridge),将抽象部分与它的实现部分分离,使它们都可以独立地变化。 - 命令模式(Command),将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤销的操作。 - 职责链模式(Chain of Responsibility),使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系。将这个对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止。 - 中介者模式(Mediator),用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。 - 享元模式(Flyweight),运用共享技术有效地支持大量细粒度的对象。 - 解释器模式(Interpreter),给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子。 - 访问者模式(Visitor),表示一个作用于某对象结构中的各元素的操作。它使你可以在不改变各元素的类的前提下定义作用于这些元素的新操作。 - - - - -设计模式的基本原则非常重要,只要真正深入地理解了设计原则,很多设计模式其实就是原则的应用而已,或许在不知不觉中就在使用设计模式了: - - 单一职责原则(SRP),就一个类而言,应该仅有一个引起它变化的原因。 +## 23种设计模式iOS实现 + +### 策略模式(Strategy) + +它定义了算法家族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户。通过一个Context指定一个Strategy,通过Strategy的子类实现不同的算法。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E7%AD%96%E7%95%A5%E6%A8%A1%E5%BC%8F.png)
+ +````objc +//策略模式配合简单工厂模式,同样的最初价格,返回不同的最终价格。不同的type就是不同的策略。 +HCDCashContext *context = [[HCDCashContext alloc]initWithCashType:CashTypeNormal]; +NSLog(@"结果是%f",[context getResult:100]); +HCDCashContext *contextReturn = [[HCDCashContext alloc]initWithCashType:CashTypeReturn]; +NSLog(@"结果是%f",[contextReturn getResult:100]); +HCDCashContext *contextRobate = [[HCDCashContext alloc]initWithCashType:CashTypeRobate]; +NSLog(@"结果是%f",[contextRobate getResult:100]); +```` + +### 装饰模式(Decorator) + +动态的给一个对象添加一些额外的职责,就增加功能来说,装饰模式比生成子类更加灵活。decorate应该像礼物一样层层封装,每一层都添加新的功能。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E8%A3%85%E9%A5%B0%E6%A8%A1%E5%BC%8F.jpg)
+ +````objc +//原始对象 +ConcreteComponent *component = [[ConcreteComponent alloc]init]; +//装饰对象 +ConcreteDecoratorA *decoratorA = [[ConcreteDecoratorA alloc]init]; +ConcreteDecoratorB *decoratorB = [[ConcreteDecoratorB alloc]init]; +//装饰对象指定原始对象,后面就是用装饰对象。这样既有原始对象的功能,也有装饰对象的功能。 +decoratorA.component = component; +decoratorB.component = component; +[decoratorA operation]; +[decoratorB operation]; + +比如iOS的扩展和分类就是装饰模式。 + +比如SDWebImage的UIView、UIImageView、UIButton的各种分类,他们都把component的部分在UIView分类中,decorator部分放在UIButton、UIImageView中。 +```` + +### 代理模式(Proxy) + +为其他对象提供一种代理以控制对这个对象的访问。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E4%BB%A3%E7%90%86%E6%A8%A1%E5%BC%8F.png)
+ +````objc +UITableView的delegate和dataSource熟悉,都是通过代理对象来控制对UITableView的访问。 +```` + +### 工厂方法模式(Factory Method) + +定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使一个类的实例化延迟到其子类。相对于简单工厂方法,工厂方法模式把工厂也抽象出来,进行接口、实现分离。这样具体工厂和具体产品可以对应着同时扩充,而不需要修改现有逻辑。当然,使用者也许在不同场景要在一定程度上自己对应的工厂选择。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E5%B7%A5%E5%8E%82%E6%96%B9%E6%B3%95%E6%A8%A1%E5%BC%8F.png)
+ +````objc +//不同的操作类有不同的工厂类,扩展新的操作不影响现有操作。HCDfactoryAdd工厂类初始化HCDCalculateAdd类。其他减、乘、除一样。 +HCDfactory *factory = [[HCDfactoryAdd alloc]init]; +HCDfactory *calculate = [factory createFactory]; +calculate.numberA = 10; +calculate.numberB = 15; +NSLog(@"结果是%f",[calculate calculate]); + +又比如NSNumber调用的具体工厂NSCFBoolean和NSCFNumber也是具体的工厂类。 +```` + +### 原型模式(Prototype) + +用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E5%8E%9F%E5%9E%8B%E6%A8%A1%E5%BC%8F.png)
+ +````objc +//NSObject类对象作为原型 +NSObject *obj = [NSObject new] +//obj对象作为原型 +NSObject *objCopy = [obj copy] +NSObject *objCopy1 = [obj copy] + +原型模式是非常简单的一种设计模式, 在多数情况下可被理解为一种深复制的行为。在Objective-C中使用原型模式, 首先要遵循NSCoping协议(OC中一些内置类遵循该协议, 例如NSArray, NSMutableArray等)。还有KVO的实现原理也是原型模式 +```` + +### 模板方法模式(Template Method) + +定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E6%A8%A1%E6%9D%BF%E6%96%B9%E6%B3%95%E6%A8%A1%E5%BC%8F.png)
+ +````objc +//HCDtextpaper定义了两个问答题的不变部分(题目),子类定义了变化部分(答案)。 +HCDtextPaper *paperA = [[HCDtextPaperA alloc]init]; +[paperA testQuestion1]; +[paperA testQuestion2]; +HCDtextPaper *paperB = [[HCDtextPaperB alloc]init]; +[paperB testQuestion1]; +[paperB testQuestion2]; + +当我们要完成在某个细节层次一致的一个过程或者一系列步骤,但是其个别步骤的更详细的层次上实现可能不同时,我们通常考虑用模板方法模式来处理。 +```` + +### 外观模式(Facade) + +为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E5%A4%96%E8%A7%82%E6%A8%A1%E5%BC%8F.png)
+ +````objc +基金经理帮我们管理不同的股票。基金经理作为外观,我们只需要让基金经理买或者卖就好,基金经理再帮我们处理不同股票的卖或者买。 + +项目中有不同的网络请求,对于每一种类型的网络请求都封装到一个固定的文件里处理,比如公用参数添加,返回数据的处理。然后再通过一个外观文件引入,直接就可以使用了。从使用来说,所有网络请求的差异都被外观文件处理了。 + +还有比如AFN对于NSURLSession的不同系统版本的处理。 +```` + +### 建造者模式(Builder) + +将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。它可以将复杂对象的建造过程抽象出来(抽象类别),使这个抽象过程的不同实现方法可以构造出不同表现(属性)的对象。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E5%BB%BA%E9%80%A0%E8%80%85%E6%A8%A1%E5%BC%8F.png)
+ +````objc +HCDPersonBuilderDirector *director = [[HCDPersonBuilderDirector alloc]init]; +HCDPresionBuilder builder = [[HCDPersonFatBuilder alloc]init]; +//为director指定builder +director.builder = builder; +//director发出构建的指令,builder负责具体的建造过程 +[director buildPerson]; + +SDWebImage的SDWebImageDownloader和SDWebImageDownloaderOperation就是director和builder之间的关系。前者不负责具体的下载操作,只负责管理builder,builder负责图片的具体下载。 +```` + +### 观察者模式(Observer) + +定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态发生变化时,会通知所有观察者对象,使它们能够自动更新自己。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E8%A7%82%E5%AF%9F%E8%80%85%E6%A8%A1%E5%BC%8F.png)
+ +````objc +iOS中的KVO、NSNotication都是观察者模式。 +```` + +### 抽象工厂模式(Abstract Factory) + +提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E6%8A%BD%E8%B1%A1%E5%B7%A5%E5%8E%82%E6%A8%A1%E5%BC%8F.png)
+ +````objc +//根据不同的工厂方法,获取不同的具体NSNumber子类对象。工厂方法和参数都不一样。通过抽象,具体初始化的是某个类根本不知道。 +[NSNumber numberWithBool:YES] +[NSNumber numberWithInt:1] +```` + +### 状态模式(State) + +当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E7%8A%B6%E6%80%81%E6%A8%A1%E5%BC%8F.png)
+ +````objc +//HCDWork对象指定不同的状态,writeProgrem会有不同的处理结果。 +HCDWork *work = [[HCDWork alloc]init]; +[work writeProgram]; +work.state = [[HCDAfternoonState alloc]init]; +[work writeProgram]; +work.state = [[HCDEventState alloc]init]; +[work writeProgram]; +work.state = [[HCDSleepState alloc]init]; +[work writeProgram]; + +比如AFN2.0的自定义Operation,有一个状态机转换规则,不同的状态下,有不同的属性设置。 +```` + +### 适配器模式(Adapter) + +将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以在一起工作。适配器模式主要应用于“希望复用一些现存的类,但是接口又与复用环境要求不一致的情况”,在遗留代码复用、类库迁移等方面非常有用。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E9%80%82%E9%85%8D%E5%99%A8%E6%A8%A1%E5%BC%8F.png)
+ +````objc +比如SDWebImage里面的SDWebImageOperation协议有一个cancel方法,所有实现了该协议的对象都有cancel方法,都可以取消。从而让不同类型的对象都可以通过同一个接口取消。比如SDWebImageDownloaderOperation、SDWebImageCombinedOperation这两个不同的对象都可以调用cancel接口。 + +还有比如Weex消息和Porsche消息之间的通过Bridge来适配消息交互。 + +android的ListView就是通过adapter来实现所有的布局和事件操作的。 +```` + +### 备忘录模式(Memento) + +在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。这样以后就可将该对象恢复到原先保存的状态。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E5%A4%87%E5%BF%98%E5%BD%95%E6%A8%A1%E5%BC%8F.png)
+ +````objc +HCDGameRoll *roll = [[HCDGameRoll alloc]init]; +[roll getState]; +//把roll对象的内部状态保存到state对象中 +HCDGameState *state = [roll saveState]; +//manager管理state对象 +HCDStateManager *manager = [[HCDStateManager alloc]initWithGameState:state]; +//改变roll的内部状态 +[roll fightBoss]; +[roll getState]; +//恢复对象的内部状态 +[roll rebackState:manager.gameState]; +[roll getState]; + +比如iOS对对象的归档接档。 +```` + +### 组合模式(Composite) + +将对象组合成树形结构以表示‘部分-整体’的层次结构。组合模式使得用户对单个对象和组合对象的使用具有一致性。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E7%BB%84%E5%90%88%E6%A8%A1%E5%BC%8F.png)
+ +````objc +//当需求中体现部分与整体层次的结构时,以及你希望用户可以忽略组合对象与单个对象的不同,统一地使用组合结构中的所有对象,接应该考虑使用组合模式了。 +HCDConcreteCompany *root = [[HCDConcreteCompany alloc]initWithName:@"总公司"]; +[root add:[[HCDHRDepartment alloc]initWithName:@"总公司人力资源部"]]; +[root add:[[HCDFinanceDepartment alloc]initWithName:@"总公司财务部"]]; + +HCDConcreteCompany *comp = [[HCDConcreteCompany alloc]initWithName:@"上海华东分公司"]; +[comp add:[[HCDHRDepartment alloc]initWithName:@"上海华东分公司人力资源部"]]; +[comp add:[[HCDFinanceDepartment alloc]initWithName:@"上海华东分公司财务部"]]; +[root add:comp]; + +HCDConcreteCompany *comp1 = [[HCDConcreteCompany alloc]initWithName:@"杭州办事处"]; +[comp1 add:[[HCDHRDepartment alloc]initWithName:@"杭州办事处人力资源部"]]; +[comp1 add:[[HCDFinanceDepartment alloc]initWithName:@"杭州办事处财务部"]]; +[root add:comp1]; +NSLog(@"结构图:----------------------------"); +[root display]; +NSLog(@"职责:---------------------------"); +[root lineofDuty]; +```` + +### 迭代器模式(Iterator) + +提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该对象的内部表示。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E8%BF%AD%E4%BB%A3%E5%99%A8%E6%A8%A1%E5%BC%8F.png)
+ +````objc +iOS的Block迭代、数组迭代都是迭代器模式的典型实现。 +```` + +### 单例模式(Singleton) + +保证一个类仅有一个实例,并提供一个访问它的全局访问点。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E5%8D%95%E5%88%97%E6%A8%A1%E5%BC%8F.png)
+ +````objc +iOS的UIApplicationDelegate就是一个单列模式的实现。 +```` + +### 桥接模式(Bridge) + +把抽象层次结构从其实现中分离出来,使其能够独立改变。抽象层定义了提供客户端使用的上层抽象接口。实现层次结构定义了供抽象层次使用的底层接口。实现类的引用被封装与抽象层的实例中。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E6%A1%A5%E6%8E%A5%E6%A8%A1%E5%BC%8F.png)
+ +````objc +比如我项目中Web与iOS/android的交互。Web只负责一套抽象的接口(Abstraction),在iOS环境和安卓环境有不同的实现(Implementor)来实现对应的功能,具体如何实现Web压根不用管。 +```` + +### 命令模式(Command) + +将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤销的操作。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E5%91%BD%E4%BB%A4%E6%A8%A1%E5%BC%8F.png)
+ +````objc +//waiter用于接收各种类型的order。waiter是请求接收者。 +//接收不同customer产生的不同order,并且都存入waiter这个接受者中,type表示不同类型的order。 +HCDWaiter *waiter = [[HCDWaiter alloc]init]; +//顾客一 +HCDCustomr *customer = [[HCDCustomr alloc]init]; +HCDOrder *customerOrder1 = [customer pushOrderWithString:@"顾客一要十串羊肉" type:orderTypeMutton]; + HCDOrder *customerOrder2 = [customer pushOrderWithString:@"顾客一要十串鸭肉" type:orderTypeDuck]; +[waiter addOrder:customerOrder1]; +[waiter addOrder:customerOrder2]; +//顾客二 +HCDCustomr *customer1 = [[HCDCustomr alloc]init]; +HCDOrder *customer1Order1 = [customer1 pushOrderWithString:@"顾客二要二十串鸡肉" type:orderTypeChicken]; + HCDOrder *customer1Order2 = [customer1 pushOrderWithString:@"顾客二要二十串鸭肉" type:orderTypeDuck]; +[waiter addOrder:customer1Order1]; +[waiter addOrder:customer1Order2]; +//顾客取消Order +[waiter deleteOrder:customer1Order2]; +//waiter发送order,背后有一个HCDWorker这个单列作为行为实现者来处理具体的order。命令接收完毕,开始发送命令。 +[waiter notifyOrder]; +```` + +### 职责链模式(Chain of Responsibility) + +使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系。将这个对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F.png)
+ +````objc +iOS事件的传递和响应就是职责链模式的实现。 +```` + +### 中介者模式(Mediator) + +用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E4%B8%AD%E4%BB%8B%E8%80%85%E6%A8%A1%E5%BC%8F.png)
+ +````objc +///根据迪米特原则,两个不相关的对象不应该直接通讯。世界各国都通过联合国这个中介者来处理纠纷利益等。 +//初始化一个中介者对象 +ConcreteMediator *mediator = [[ConcreteMediator alloc]init]; +//初始化并且让两个同事有相同的中介者对象 +ConcreteColleague1 *c1 = [[ConcreteColleague1 alloc]initWithMediator:mediator]; +ConcreteColleague2 *c2 = [[ConcreteColleague2 alloc]initWithMediator:mediator]; +//给中介者对象绑定两个要交互的同事对象 +mediator.colleague1 = c1; +mediator.colleague2 = c2; +//c1和c2都通过mediator发送信息 +[c1 send:@"吃过饭了吗?"]; +[c2 send:@"没有呢,你打算请客?"]; +```` + +### 享元模式(Flyweight) + +运用共享技术有效地支持大量细粒度的对象。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E4%BA%AB%E5%85%83%E6%A8%A1%E5%BC%8F.png)
+ +````objc +比如iOS的RunTime就是享元的一个事件。每个对象调用的方法其实是他对应的类里面实现的。比如NSObject定义了很多方法让所有对象都可以使用。类对象永远只有一个,而对应的实例对象有无数个。 + +//享元工厂,里面包括多个共享的对象。 +HCDWebSiteFactory *facoty = [[HCDWebSiteFactory alloc]init]; +//虽然生成了两个fx和fy产品展示类型的对象,但是通过共享只初始化了一个产品展示的对象。 +HCDWebSiteType fx = [facoty getWebSiteCategory:@"产品展示"]; +HCDUser *user = [[HCDUser alloc]init]; +user.name = @"小菜"; +[fx use:user]; +HCDWebSiteType fy = [facoty getWebSiteCategory:@"产品展示"]; +HCDUser *user1 = [[HCDUser alloc]init]; +user1.name = @"大鸟"; +[fy use:user1]; +//初始化一个博客类型的对象。以后使用都可以共享使用,因为他们有基本相似的功能。 +HCDWebSiteType fz = [facoty getWebSiteCategory:@"博客"]; +HCDUser *user2 = [[HCDUser alloc]init]; +user2.name = @"咪咪"; +[fz use:user2]; +```` + +### 解释器模式(Interpreter) + +给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子。
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E8%A7%A3%E9%87%8A%E5%99%A8%E6%A8%A1%E5%BC%8F.png)
+ +````objc +比如JavaScript中,判断邮件地址、电话号码、证件号码是否正确的正则表达式,每一个表达式就是一个解释器。 +又比如外交部的发言。就需要解释器来解释特定的内容。达成共识(扯淡了半天),充分表达了立场(撕逼了半天),我不了解相关情况(我不想回答你的问题)。 + +//用于存放一些全局配置信息 +HCDContext *context = [[HCDContext alloc]initWithInput:@"12345"]; +NSMutableArray *list = [[NSMutableArray alloc]init]; +//不同的解释器 +[list addObject:[[HCDTerminalExpression alloc]init]]; +[list addObject:[[HCDNonterminalExpression alloc]init]]; +[list addObject:[[HCDTerminalExpression alloc]init]]; +[list addObject:[[HCDTerminalExpression alloc]init]]; +//获得不同解释器的解释结果 +for(HCDAbstractExpression *exp in list) { + [exp interpret:context]; +} +```` + +### 访问者模式(Visitor) + +表示一个作用于某对象结构中的各元素的操作。它使你可以在不改变各元素的类(男人,女人)的前提下定义作用于这些元素的新操作(喜怒哀乐)。他把数据结构(男人,女人)和作用于数据结构之上的操作(喜怒哀乐)之间的耦合解脱开,使得操作集合可以相对自由地演化
+![img](https://github.com/huang303513/Design-Pattern-For-iOS/blob/master/%E8%AE%BE%E8%AE%A1%E5%9B%BE/%E8%AE%BF%E9%97%AE%E8%80%85%E6%A8%A1%E5%BC%8F.png)
+ +````objc +访问者模式的有点就是增加新的操作很容易,因为增加新的操作就意味着增加一个新的访问者。 +/* + HCDConcreteElementA和HCDConcreteElementB相当于男人女人(固定不变),当男人女人接收到喜怒哀乐(HCDConcreteVisitor1,HCDConcreteVisitor2)有不同的结果。HCDObjectStructure用于管理他们之间的关系。 + */ +HCDObjectStructure *o = [[HCDObjectStructure alloc]init]; +//初始化不同的element对象 +HCDConcreteElementA *eA = [HCDConcreteElementA new]; +HCDConcreteElementB *eB = [HCDConcreteElementB new]; +//加入o对象里面,存在一个数据结构o中。 +[o attach:eA]; +[o attach:eB]; +//初始化不同的visitor对象。 +HCDConcreteVisitor1 *v1 = [HCDConcreteVisitor1 new]; +HCDConcreteVisitor2 *v2 = [HCDConcreteVisitor2 new]; +//eA,eB(男人女人)接收到访问者v1(喜)的不同反应。 +[o accept: v1]; +NSLog(@"================================"); +//eA,eB(男人女人)接收到访问者v2(怒)的不同反应。 +[o accept: v2]; +```` + +## 六个原则 + + 单一职责原则(SRP),就一个类而言,只做一件事。 开放-封闭原则(OCP),是说软件实体(类、模块、函数等等)应该可以拓展,但是不可修改。 依赖倒转原则(DIP),A. 高层模块不应该依赖低层模块,两个都应该依赖抽象。B. 抽象不应该依赖细节,细节应该依赖抽象。 里氏代换原则(LSP),子类型必须能够替换掉它们的父类型。 迪米特法则(LoD),如果两个类不必彼此直接通信,那么这两个类就不应当发生直接的相互作用。如果其中一个类需要调用另一个类的某一个方法的话,可以通过第三者转发这个调用。 合成/聚合复用原则(CARP),尽量使用合成/聚合,尽量不要使用类继承。 +## 参考博文推荐: + +[Cocoa如何应用设计模式](http://www.cnblogs.com/pengyingh/articles/2346299.html) + +[大话设计模式阅读笔记](http://www.jianshu.com/p/47c67255c842) + +[设计模式问答一](http://mp.weixin.qq.com/s?__biz=MzAxNzA1ODY2OA==&mid=204772288&idx=1&sn=182ebf11253f80579f386f0c9cf4750e#rd) + +[设计模式问答二](http://mp.weixin.qq.com/s?__biz=MzAxNzA1ODY2OA==&mid=205051580&idx=1&sn=8dfca32f8598544922ff0adc8a6f76a4#rd) + +[设计模式问答三](http://mp.weixin.qq.com/s?__biz=MzAxNzA1ODY2OA==&mid=205377346&idx=1&sn=1ea5f7328e5f545984c2c54a84a54a93#rd) + +[设计模式问答四](http://mp.weixin.qq.com/s?__biz=MzAxNzA1ODY2OA==&mid=205598648&idx=1&sn=4351450c6168c4c318ca362741ac152e#rd) + diff --git "a/\350\256\276\350\256\241\345\233\276/\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.png" new file mode 100644 index 0000000..6f64552 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\344\270\255\344\273\213\350\200\205\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\344\272\253\345\205\203\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\344\272\253\345\205\203\346\250\241\345\274\217.png" new file mode 100644 index 0000000..0a32f82 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\344\272\253\345\205\203\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\344\273\243\347\220\206\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\344\273\243\347\220\206\346\250\241\345\274\217.png" new file mode 100644 index 0000000..d65038f Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\344\273\243\347\220\206\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\345\215\225\345\210\227\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\345\215\225\345\210\227\346\250\241\345\274\217.png" new file mode 100644 index 0000000..c4f870b Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\345\215\225\345\210\227\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\345\216\237\345\236\213\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\345\216\237\345\236\213\346\250\241\345\274\217.png" new file mode 100644 index 0000000..269ece5 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\345\216\237\345\236\213\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\345\221\275\344\273\244\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\345\221\275\344\273\244\346\250\241\345\274\217.png" new file mode 100644 index 0000000..ff01846 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\345\221\275\344\273\244\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\345\244\207\345\277\230\345\275\225\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\345\244\207\345\277\230\345\275\225\346\250\241\345\274\217.png" new file mode 100644 index 0000000..fcd7589 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\345\244\207\345\277\230\345\275\225\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\345\244\226\350\247\202\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\345\244\226\350\247\202\346\250\241\345\274\217.png" new file mode 100644 index 0000000..858db7c Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\345\244\226\350\247\202\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\345\267\245\345\216\202\346\226\271\346\263\225\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\345\267\245\345\216\202\346\226\271\346\263\225\346\250\241\345\274\217.png" new file mode 100644 index 0000000..265c95b Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\345\267\245\345\216\202\346\226\271\346\263\225\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217.png" new file mode 100644 index 0000000..a4880e7 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\345\273\272\351\200\240\350\200\205\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\346\212\275\350\261\241\345\267\245\345\216\202\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\346\212\275\350\261\241\345\267\245\345\216\202\346\250\241\345\274\217.png" new file mode 100644 index 0000000..64f5357 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\346\212\275\350\261\241\345\267\245\345\216\202\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\346\241\245\346\216\245\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\346\241\245\346\216\245\346\250\241\345\274\217.png" new file mode 100644 index 0000000..b3d549c Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\346\241\245\346\216\245\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\346\250\241\346\235\277\346\226\271\346\263\225\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\346\250\241\346\235\277\346\226\271\346\263\225\346\250\241\345\274\217.png" new file mode 100644 index 0000000..e73dc1c Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\346\250\241\346\235\277\346\226\271\346\263\225\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\347\212\266\346\200\201\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\347\212\266\346\200\201\346\250\241\345\274\217.png" new file mode 100644 index 0000000..d525cfb Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\347\212\266\346\200\201\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\347\255\226\347\225\245\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\347\255\226\347\225\245\346\250\241\345\274\217.png" new file mode 100644 index 0000000..7c8ddcf Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\347\255\226\347\225\245\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.png" new file mode 100644 index 0000000..577f8f8 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xml" "b/\350\256\276\350\256\241\345\233\276/\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xml" new file mode 100644 index 0000000..84c1677 --- /dev/null +++ "b/\350\256\276\350\256\241\345\233\276/\347\256\200\345\215\225\345\267\245\345\216\202\346\250\241\345\274\217.xml" @@ -0,0 +1 @@ +7Vpdc9o4FP01zLQP20H+gjwGp2kf0k5m2ZntPgpbYE1li5FFgP76vcKSvwkmEJMHZ5hEurqSpXvOPcKKRrYf774JvI5+8JCwkTUOdyP7YWRZaOxM4I+y7DOL57iZYSVoqJ0Kw5z+Iaantm5oSNKKo+ScSbquGgOeJCSQFRsWgm+rbkvOqk9d4xVpGOYBZk3rvzSUUWadWl5h/07oKjJPRt5d1rLAwe+V4JtEP29k2cvDT9YcYzOWXmga4ZBvSyb768j2BecyK8U7nzAVWxO2rN/jkdZ83oIksksHjdMLZhtiZuwx6DqjUFipwnf/wccs2DAsiWmEAfN2vRC5N8FLtzRmOIHaLJIxAyOC4pIncq6dVB0zukqgHMBMiQDDCxGSAgT3ukHyNViDiLLwCe/5Rq0nlRBfU5tFXNA/MCw2z4BmITWbAKuyx1z1BPMYrIKk4PNsgoRy0xNOpfYJOGN4ndJFPuEYixVNZlxKHmsns9JHypjPGReHABjETWjUwsjuKEAohx3SifCYSLEHF93B1UTRiWQYuC1YiTztEpUZOXZ0NuhMWOUjF2yAgiZEOzmmLeSANY2TTbwg4h5KI1v99r89Mo6lIcdCFNQo3GdN9xpvIEiyyplUCv6bmMgm/MCpZSnY2mS4xMhSHmVSusYBTVZPB58Hp7D8rcOmTNuISjIHu5rTFsQNbBzGW7JDlkY0DEmi+MIlljgjh2LCmtNEHkLtzuADiPjjL+7IhXX5UEdFHT7KXUifJ7A+TA88IMC8LUllV9JM2klzJkucK5DkroUkNWAZrYtBBqyRVvQmVGPAQj3BwPiPQvnhL9SA2m5CbbdAyPCCsGeeUkm5Gl9kvjVoe0BvMu6G3vRy8Mx+20jxwCj+p89D3vaWt5NpN+RNfl8EPWpAX93ph139/XZ1VNvVnY4p710j5+1Bsc/OW3QEzzM33GvA5wyS3atkn4DednrUbG/Q7Ntp9t0tRbvtRX0Q7RN4eh9GtI+9Sg+i/U6i/Tr0vYp28w15EO2+RNv2bijaVtvb9SDaJ/C8+yiibTXfkAfRflfRfh36PkXbZOog2rf4n4dzS9EejkfOz9wsRh9CtIfjkX5F+wT0vYq2+6poP+JAcj3ioN3vpN3WtKrdDmrgn7uU8Z9c4V+RrbcZBuk+kb/uudLdit81pPvoIYkgkL55Hn/6OZ9LARH8nKk49Lc8HKvsO9w/qF1YyVrar6oMQn81orQIfStR7CsIvd38dt6AliThvboJpiSb4TSlQRVosqPylw6lKv+nyl9gkVBNYD6/jJ+qZI1oahnDMxEUpq02gsMI2eNJ2LhWVtNNmCLfiIBUNyzYBlaknEjNKJfC6rZE1dgEAdbTl+os2kKtn/CsSFRSb7uq3sgcYZghstnrXgVgzYGs6kBebZxsxY1xDsDnq+7GhQ6iX+LCgnG1rwKK5toh8rKq2hQ1miWadAe2DCIan0Qx/xZ0IWTI3MAxkE3eCBmqY+90wwwii/clN61LF6La/VpRdf+22uC76BtN7QQRtVzPcSctKYlq4XuL0DndTxCbYQipIIH+AgEkUPYrh8Z1a6FxG6FBba/p7hUi03Y493Eik1/iukVoOuyONwyN49wwNN0Pd24RGs/qLaGgWtwyzwS6uMpvf/0f \ No newline at end of file diff --git "a/\350\256\276\350\256\241\345\233\276/\347\273\204\345\220\210\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\347\273\204\345\220\210\346\250\241\345\274\217.png" new file mode 100644 index 0000000..e2e4ffb Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\347\273\204\345\220\210\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\350\243\205\351\245\260\346\250\241\345\274\217.jpg" "b/\350\256\276\350\256\241\345\233\276/\350\243\205\351\245\260\346\250\241\345\274\217.jpg" new file mode 100644 index 0000000..12ff2ef Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\350\243\205\351\245\260\346\250\241\345\274\217.jpg" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\350\247\202\345\257\237\350\200\205\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\350\247\202\345\257\237\350\200\205\346\250\241\345\274\217.png" new file mode 100644 index 0000000..8633ff6 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\350\247\202\345\257\237\350\200\205\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\350\247\243\351\207\212\345\231\250\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\350\247\243\351\207\212\345\231\250\346\250\241\345\274\217.png" new file mode 100644 index 0000000..dfa0f37 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\350\247\243\351\207\212\345\231\250\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.png" new file mode 100644 index 0000000..e4f29f1 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\350\256\277\351\227\256\350\200\205\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\350\264\243\344\273\273\351\223\276\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\350\264\243\344\273\273\351\223\276\346\250\241\345\274\217.png" new file mode 100644 index 0000000..278f530 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\350\264\243\344\273\273\351\223\276\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\350\277\255\344\273\243\345\231\250\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\350\277\255\344\273\243\345\231\250\346\250\241\345\274\217.png" new file mode 100644 index 0000000..1f97199 Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\350\277\255\344\273\243\345\231\250\346\250\241\345\274\217.png" differ diff --git "a/\350\256\276\350\256\241\345\233\276/\351\200\202\351\205\215\345\231\250\346\250\241\345\274\217.png" "b/\350\256\276\350\256\241\345\233\276/\351\200\202\351\205\215\345\231\250\346\250\241\345\274\217.png" new file mode 100644 index 0000000..87a8b2b Binary files /dev/null and "b/\350\256\276\350\256\241\345\233\276/\351\200\202\351\205\215\345\231\250\346\250\241\345\274\217.png" differ