Last active
December 15, 2015 18:39
-
-
Save b-adams/5305279 to your computer and use it in GitHub Desktop.
Revisions
-
Prof. Bryant E Adams revised this gist
Apr 3, 2013 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,3 +15,20 @@ -(Pizza*) createPizza(NSString* type) return pizza; } @end //More idiomatic Objective-C @implementation SimplePizzaFactory -(Pizza*) createPizza(NSString* type) { NSDictionary* pizzaTypes = @{ @"cheese": [CheesePizza class], @"pepperoni": [PepperoniPizza class], @"clam": [ClamPizza class], @"veggie": [VeggiePizza class] }; Class pizzaClass = [pizzaTypes objectForKey:type]; Pizza* pizza = [[pizzaClass alloc] init]; return pizza; } @end -
Prof. Bryant E Adams revised this gist
Apr 3, 2013 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ @interface PizzaStore : NSObject @property (strong, readwrite) SimplePizzaFactory* factory; @end @implementation PizzaStore -(id)initWithFactory:(SimplePizzaFactory* factory) { self = [super init]; -
Prof. Bryant E Adams created this gist
Apr 3, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ Duck* duck = [[MallardDuck alloc] init]; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ Duck* duck; if(picnic) { duck = [[MallardDuck alloc] init]; } else if(hunting) { duck = [[DecoyDuck alloc] init]; } else if(inBathTub) { duck = [[RubberDuck alloc] init]; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ -(Pizza*) orderPizza { Pizza* pizza = [[Pizza alloc] init]; [pizza prepare]; [pizza bake]; [pizza cut]; [pizza box]; return pizza; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ -(Pizza*) orderPizza:(NSString* type) { Pizza* pizza = [[Pizza alloc] init]; if([type isEqualToString:@"cheese"]) { pizza = [[CheesePizza alloc] init]; } else if([type isEqualToString:@"greek"]) { pizza = [[GreekPizza alloc] init]; } else if([type isEqualToString:@"pepperoni"]) { pizza = [[PepperoniPizza alloc] init]; } [pizza prepare]; [pizza bake]; [pizza cut]; [pizza box]; return pizza; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ -(Pizza*) orderPizza:(NSString* type) { Pizza* pizza; if([type isEqualToString:@"cheese"]) { pizza = [[CheesePizza alloc] init]; // } else if([type isEqualToString:@"greek"]) { // pizza = [[GreekPizza alloc] init]; } else if([type isEqualToString:@"pepperoni"]) { pizza = [[PepperoniPizza alloc] init]; } else if([type isEqualToString:@"clam"]) { pizza = [[ClamPizza alloc] init]; } else if([type isEqualToString:@"veggie"]) { pizza = [[VeggiePizza alloc] init]; } [pizza prepare]; [pizza bake]; [pizza cut]; [pizza box]; return pizza; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ @implementation SimplePizzaFactory -(Pizza*) createPizza(NSString* type) { Pizza* pizza = nil; if([type isEqualToString:@"cheese"]) { pizza = [[CheesePizza alloc] init]; } else if([type isEqualToString:@"pepperoni"]) { pizza = [[PepperoniPizza alloc] init]; } else if([type isEqualToString:@"clam"]) { pizza = [[ClamPizza alloc] init]; } else if([type isEqualToString:@"veggie"]) { pizza = [[VeggiePizza alloc] init]; } return pizza; } @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ @implementation PizzaStore { SimplePizzaFactory* factory; } -(id)initWithFactory:(SimplePizzaFactory* factory) { self = [super init]; if(self) { [self setFactory:factory]; } return self; } -(Pizza*) orderPizza:(NSString* type) { Pizza* pizza; pizza = [factory createPizza:type]; [pizza prepare]; [pizza bake]; [pizza cut]; [pizza box]; return pizza; } // other methods here @end