Successfully reported this slideshow.

Epic Refactorings - Melbourne Cocoaheads June 2011

0

Share

Upcoming SlideShare
React js intro
React js intro
Loading in …3
×
1 of 41
1 of 41

Epic Refactorings - Melbourne Cocoaheads June 2011

0

Share

Download to read offline

Description

By Jesse Collis and Luke Cunningham. June 2011

Transcript

  1. 1. epic refactorings and patterns to make your jesse collis (@sirjec) code awesome luke cunningham (@icaruswings)
  2. 2. firstly, read this book!
  3. 3. insert a pic of us reading our books having a ‘lightbulb’ moment we did and it made us better engineers
  4. 4. we do agile...
  5. 5. write the minimum amount of code to implement the story
  6. 6. 12 months later...
  7. 7. 1 small card
  8. 8. But that isn’t what this talk is about
  9. 9. the problem just too much for one view controller
  10. 10. First Diagram
  11. 11. alright stop! refactor time.
  12. 12. first problem
  13. 13. view controllers need only worry about standard UIViews and manage the display.
  14. 14. coordination and containment!
  15. 15. ViewCoordinator view lifecycle
  16. 16. @protocol ViewCoordinator <NSObject> - (UIView *)view; - (void)viewWillAppear; - (void)viewDidAppear; - (void)viewWillDisappear; - (void)viewDidDisappear; - (void)viewDidUnload; - (void)didReceiveMemoryWarning; @end
  17. 17. @interface YourViewController : UIViewController { id<ViewCoordinator> viewCoordinator_; } ... @end
  18. 18. @implementation YourViewController - (id)initWithNibName... { viewCoordinator_ = [[MyViewCoordinator alloc] init]; } - (void)loadView { [super loadView]; [self.view addSubview:[viewCoordinator_ view]]; } - (void)viewWillAppear { [[viewCoordinator_ view] viewWillAppear]; } ... @end
  19. 19. single responsibility a class should only have one reason to change.
  20. 20. second problem
  21. 21. they’re not simple views
  22. 22. ListCoordinator basic selection callbacks
  23. 23. @protocol ListCoordinator - (void)onSelectListItem:^(id)block; ... @end
  24. 24. @interface YourViewController : UIViewController { id<ViewCoordinator> viewCoordinator_; id<ViewCoordinator, ListViewCoordinator> listCoordinator_; } ... @end
  25. 25. @implementation YourViewController - (id)initWithNibName... { listCoordinator_ = [[MyListCoordinator alloc] init]; [listCoordinator_ onSelectListItem:^(id listing) { [self showListing:listing]; }]; } - (void)showListing:(Listing *)listing;{ ... } ... @end
  26. 26. interface segregation clients should not be forced to depend on methods they don’t use.
  27. 27. QueryCoordinator after configure/ cancel configure callbacks
  28. 28. SearchBarCoord... and so on...
  29. 29. now our structure is more like this...
  30. 30. Go to Xcode
  31. 31. under the hood
  32. 32. EventDispatcher
  33. 33. @interface MapCooordinator <ViewCoordinator, ListCoordinator> { ... } @end
  34. 34. @implementation MapCoordinator ... - (void)onSelectListItem:^(Listing *)block; { [eventDispatcher_ on:@"select-listing” performWithObject:block]; } - (void)mapView:(... *)mapView didSelectAnnotationView:(... *)view; { Listing *listing = ... find listing ... [eventDispatcher_ fire:@"select-listing" withObject:listing]; } ... @end
  35. 35. there are no special cases
  36. 36. If you implement patterns - follow your patterns
  37. 37. Coming in iOS5
  38. 38. thanks, jesse collis (@sirjec) luke cunningham (@icaruswings)

Description

By Jesse Collis and Luke Cunningham. June 2011

Transcript

  1. 1. epic refactorings and patterns to make your jesse collis (@sirjec) code awesome luke cunningham (@icaruswings)
  2. 2. firstly, read this book!
  3. 3. insert a pic of us reading our books having a ‘lightbulb’ moment we did and it made us better engineers
  4. 4. we do agile...
  5. 5. write the minimum amount of code to implement the story
  6. 6. 12 months later...
  7. 7. 1 small card
  8. 8. But that isn’t what this talk is about
  9. 9. the problem just too much for one view controller
  10. 10. First Diagram
  11. 11. alright stop! refactor time.
  12. 12. first problem
  13. 13. view controllers need only worry about standard UIViews and manage the display.
  14. 14. coordination and containment!
  15. 15. ViewCoordinator view lifecycle
  16. 16. @protocol ViewCoordinator <NSObject> - (UIView *)view; - (void)viewWillAppear; - (void)viewDidAppear; - (void)viewWillDisappear; - (void)viewDidDisappear; - (void)viewDidUnload; - (void)didReceiveMemoryWarning; @end
  17. 17. @interface YourViewController : UIViewController { id<ViewCoordinator> viewCoordinator_; } ... @end
  18. 18. @implementation YourViewController - (id)initWithNibName... { viewCoordinator_ = [[MyViewCoordinator alloc] init]; } - (void)loadView { [super loadView]; [self.view addSubview:[viewCoordinator_ view]]; } - (void)viewWillAppear { [[viewCoordinator_ view] viewWillAppear]; } ... @end
  19. 19. single responsibility a class should only have one reason to change.
  20. 20. second problem
  21. 21. they’re not simple views
  22. 22. ListCoordinator basic selection callbacks
  23. 23. @protocol ListCoordinator - (void)onSelectListItem:^(id)block; ... @end
  24. 24. @interface YourViewController : UIViewController { id<ViewCoordinator> viewCoordinator_; id<ViewCoordinator, ListViewCoordinator> listCoordinator_; } ... @end
  25. 25. @implementation YourViewController - (id)initWithNibName... { listCoordinator_ = [[MyListCoordinator alloc] init]; [listCoordinator_ onSelectListItem:^(id listing) { [self showListing:listing]; }]; } - (void)showListing:(Listing *)listing;{ ... } ... @end
  26. 26. interface segregation clients should not be forced to depend on methods they don’t use.
  27. 27. QueryCoordinator after configure/ cancel configure callbacks
  28. 28. SearchBarCoord... and so on...
  29. 29. now our structure is more like this...
  30. 30. Go to Xcode
  31. 31. under the hood
  32. 32. EventDispatcher
  33. 33. @interface MapCooordinator <ViewCoordinator, ListCoordinator> { ... } @end
  34. 34. @implementation MapCoordinator ... - (void)onSelectListItem:^(Listing *)block; { [eventDispatcher_ on:@"select-listing” performWithObject:block]; } - (void)mapView:(... *)mapView didSelectAnnotationView:(... *)view; { Listing *listing = ... find listing ... [eventDispatcher_ fire:@"select-listing" withObject:listing]; } ... @end
  35. 35. there are no special cases
  36. 36. If you implement patterns - follow your patterns
  37. 37. Coming in iOS5
  38. 38. thanks, jesse collis (@sirjec) luke cunningham (@icaruswings)

More Related Content

Related Books

Free with a 30 day trial from Scribd

See all

×