Epic Refactorings - Melbourne Cocoaheads June 2011

Jesse Collis
Jesse CollisFreelance iOS/PHP Developer at Beanhunter
epic refactorings and
patterns to make
your jesse collis (@sirjec)
      code awesome
     luke cunningham (@icaruswings)
firstly, read this book!
insert a pic of us
reading our books
having a
‘lightbulb’ moment



    we did and it
    made us better
    engineers
we do agile...
Epic Refactorings - Melbourne Cocoaheads June 2011
write the minimum
amount of code to
implement the story
12 months later...
1 small card
Epic Refactorings - Melbourne Cocoaheads June 2011
But that isn’t
what this talk is
about
the problem
just too much for one
view controller
First Diagram
alright stop!
refactor time.
first problem
view controllers need
only worry about
standard UIViews and
manage the display.
coordination and
containment!
ViewCoordinator
view lifecycle
@protocol ViewCoordinator <NSObject>

- (UIView *)view;

- (void)viewWillAppear;

- (void)viewDidAppear;

- (void)viewWillDisappear;

- (void)viewDidDisappear;

- (void)viewDidUnload;

- (void)didReceiveMemoryWarning;

@end
@interface YourViewController : UIViewController {

 id<ViewCoordinator> viewCoordinator_;

}

...

@end
@implementation YourViewController

- (id)initWithNibName... {
 viewCoordinator_ = [[MyViewCoordinator alloc] init];
}

- (void)loadView {
 [super loadView];
 [self.view addSubview:[viewCoordinator_ view]];
}

- (void)viewWillAppear {
 [[viewCoordinator_ view] viewWillAppear];
}

...

@end
single responsibility

a class should only
have one reason to
change.
second problem
they’re not
simple views
ListCoordinator
basic selection
callbacks
@protocol ListCoordinator

- (void)onSelectListItem:^(id)block;

...

@end
@interface YourViewController : UIViewController {

 id<ViewCoordinator> viewCoordinator_;

 id<ViewCoordinator, ListViewCoordinator> listCoordinator_;

}

...

@end
@implementation YourViewController

- (id)initWithNibName... {
 listCoordinator_ = [[MyListCoordinator alloc] init];


 [listCoordinator_ onSelectListItem:^(id listing) {
      [self showListing:listing];
 }];
}

- (void)showListing:(Listing *)listing;{

...

}

...

@end
interface segregation
clients should not
be forced to depend
on methods they
don’t use.
QueryCoordinator
after configure/
cancel configure
callbacks
SearchBarCoord...



and so on...
now our
structure is more
like this...
Epic Refactorings - Melbourne Cocoaheads June 2011
Go to Xcode
under the hood
EventDispatcher
@interface MapCooordinator <ViewCoordinator, ListCoordinator>
{
    ...
}

@end
@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
there are no
special cases
If you implement
patterns -
follow your patterns
Coming in iOS5
thanks,
  jesse collis (@sirjec)
  luke cunningham (@icaruswings)
1 of 41

Recommended

React js intro by
React js introReact js intro
React js introJessica Le
451 views7 slides
Backbone And Marionette : Take Over The World by
Backbone And Marionette : Take Over The WorldBackbone And Marionette : Take Over The World
Backbone And Marionette : Take Over The Worldharshit040591
794 views33 slides
Marionette - TorontoJS by
Marionette - TorontoJSMarionette - TorontoJS
Marionette - TorontoJSmatt-briggs
2.9K views27 slides
Marionette structure with modules by
Marionette structure with modulesMarionette structure with modules
Marionette structure with modulesmatt-briggs
11.1K views18 slides
Backbone/Marionette introduction by
Backbone/Marionette introductionBackbone/Marionette introduction
Backbone/Marionette introductionmatt-briggs
4.6K views20 slides
Seminar Konfliktens Anatomi by
Seminar Konfliktens AnatomiSeminar Konfliktens Anatomi
Seminar Konfliktens Anatomimarga_dijkman
397 views4 slides

More Related Content

Viewers also liked

CATiled Layer - Melbourne Cocoheads February 2012 by
CATiled Layer - Melbourne Cocoheads February 2012CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012Jesse Collis
862 views24 slides
Terra malalta by
Terra malaltaTerra malalta
Terra malaltae3005339
236 views22 slides
Bedre Samarbeid, Kommunikasjon og Stressmestring i en travel arbeidsdag by
Bedre Samarbeid, Kommunikasjon og Stressmestring i en travel arbeidsdagBedre Samarbeid, Kommunikasjon og Stressmestring i en travel arbeidsdag
Bedre Samarbeid, Kommunikasjon og Stressmestring i en travel arbeidsdagmarga_dijkman
894 views12 slides
Habitats by
HabitatsHabitats
Habitatse3005339
298 views54 slides
Diffusion meeting Spain by
Diffusion meeting SpainDiffusion meeting Spain
Diffusion meeting Spaine3005339
620 views3 slides
LOGO CONTEST by
LOGO CONTESTLOGO CONTEST
LOGO CONTESTe3005339
297 views3 slides

Viewers also liked(13)

CATiled Layer - Melbourne Cocoheads February 2012 by Jesse Collis
CATiled Layer - Melbourne Cocoheads February 2012CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012
Jesse Collis862 views
Terra malalta by e3005339
Terra malaltaTerra malalta
Terra malalta
e3005339236 views
Bedre Samarbeid, Kommunikasjon og Stressmestring i en travel arbeidsdag by marga_dijkman
Bedre Samarbeid, Kommunikasjon og Stressmestring i en travel arbeidsdagBedre Samarbeid, Kommunikasjon og Stressmestring i en travel arbeidsdag
Bedre Samarbeid, Kommunikasjon og Stressmestring i en travel arbeidsdag
marga_dijkman894 views
Habitats by e3005339
HabitatsHabitats
Habitats
e3005339298 views
Diffusion meeting Spain by e3005339
Diffusion meeting SpainDiffusion meeting Spain
Diffusion meeting Spain
e3005339620 views
LOGO CONTEST by e3005339
LOGO CONTESTLOGO CONTEST
LOGO CONTEST
e3005339297 views
La Primavera by e3005339
La PrimaveraLa Primavera
La Primavera
e3005339177 views
A Brief History of Melbourne Cocoaheads - May 2013 by Jesse Collis
A Brief History of Melbourne Cocoaheads - May 2013A Brief History of Melbourne Cocoaheads - May 2013
A Brief History of Melbourne Cocoaheads - May 2013
Jesse Collis1.3K views
editorial by lionred17
editorialeditorial
editorial
lionred17120 views
Integrating iAds (Melbourne Cocoaheads November 2010) by Jesse Collis
Integrating iAds (Melbourne Cocoaheads November 2010)Integrating iAds (Melbourne Cocoaheads November 2010)
Integrating iAds (Melbourne Cocoaheads November 2010)
Jesse Collis856 views
Writing Online News Leads by Bill Edwards
Writing Online News LeadsWriting Online News Leads
Writing Online News Leads
Bill Edwards686 views
Implementing CATiledLayer by Jesse Collis
Implementing CATiledLayerImplementing CATiledLayer
Implementing CATiledLayer
Jesse Collis7.2K views
Xcode 4 shortcuts (Melbourne Cocoheads April 2011) by Jesse Collis
Xcode 4 shortcuts (Melbourne Cocoheads April 2011)Xcode 4 shortcuts (Melbourne Cocoheads April 2011)
Xcode 4 shortcuts (Melbourne Cocoheads April 2011)
Jesse Collis2.6K views

Similar to Epic Refactorings - Melbourne Cocoaheads June 2011

React.js - and how it changed our thinking about UI by
React.js - and how it changed our thinking about UIReact.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIMarcin Grzywaczewski
2.5K views25 slides
ngSummit 2017: Angular meets Redux by
ngSummit 2017: Angular meets ReduxngSummit 2017: Angular meets Redux
ngSummit 2017: Angular meets ReduxMichał Michalczuk
120 views31 slides
Welcome to React & Flux ! by
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !Ritesh Kumar
548 views28 slides
All the reasons for choosing react js that you didn't know about - Avi Marcus... by
All the reasons for choosing react js that you didn't know about - Avi Marcus...All the reasons for choosing react js that you didn't know about - Avi Marcus...
All the reasons for choosing react js that you didn't know about - Avi Marcus...Codemotion Tel Aviv
2.6K views20 slides
IOS Storyboards by
IOS StoryboardsIOS Storyboards
IOS StoryboardsMuhammad Nabeel Arif
1.5K views24 slides
Intro to AngularJs by
Intro to AngularJsIntro to AngularJs
Intro to AngularJsSolTech, Inc.
536 views37 slides

Similar to Epic Refactorings - Melbourne Cocoaheads June 2011(20)

React.js - and how it changed our thinking about UI by Marcin Grzywaczewski
React.js - and how it changed our thinking about UIReact.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UI
Welcome to React & Flux ! by Ritesh Kumar
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
Ritesh Kumar548 views
All the reasons for choosing react js that you didn't know about - Avi Marcus... by Codemotion Tel Aviv
All the reasons for choosing react js that you didn't know about - Avi Marcus...All the reasons for choosing react js that you didn't know about - Avi Marcus...
All the reasons for choosing react js that you didn't know about - Avi Marcus...
Codemotion Tel Aviv2.6K views
Why you should consider a microframework for your next web project by Joaquín Muñoz M.
Why you should consider a microframework for your next web projectWhy you should consider a microframework for your next web project
Why you should consider a microframework for your next web project
Joaquín Muñoz M.509 views
Design Patterns in ZK: Java MVVM as Model-View-Binder by Simon Massey
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-Binder
Simon Massey13.3K views
Bringing Swift into your Objective-C Projects by René Cacheaux
Bringing Swift into your Objective-C ProjectsBringing Swift into your Objective-C Projects
Bringing Swift into your Objective-C Projects
René Cacheaux2K views
Reusing your frontend JS on the server with V8/Rhino by Kenneth Kalmer
Reusing your frontend JS on the server with V8/RhinoReusing your frontend JS on the server with V8/Rhino
Reusing your frontend JS on the server with V8/Rhino
Kenneth Kalmer1.1K views
Android howto hellowidget by Hiron Das
Android howto hellowidgetAndroid howto hellowidget
Android howto hellowidget
Hiron Das492 views
iOS UIStoryboard presentation by Gerald Kim
iOS UIStoryboard presentationiOS UIStoryboard presentation
iOS UIStoryboard presentation
Gerald Kim2K views
Yeoman AngularJS and D3 - A solid stack for web apps by climboid
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web apps
climboid16.1K views
CQRS recipes or how to cook your architecture by Thomas Jaskula
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
Thomas Jaskula18K views
KnockOutjs from Scratch by Udaya Kumar
KnockOutjs from ScratchKnockOutjs from Scratch
KnockOutjs from Scratch
Udaya Kumar626 views

Recently uploaded

What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueShapeBlue
222 views23 slides
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlueShapeBlue
103 views23 slides
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool by
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPoolShapeBlue
84 views10 slides
The Power of Heat Decarbonisation Plans in the Built Environment by
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built EnvironmentIES VE
69 views20 slides
Data Integrity for Banking and Financial Services by
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial ServicesPrecisely
78 views26 slides
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... by
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...ShapeBlue
79 views17 slides

Recently uploaded(20)

What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue222 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue103 views
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool by ShapeBlue
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool
ShapeBlue84 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE69 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely78 views
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... by ShapeBlue
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
ShapeBlue79 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash153 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc160 views
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue210 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue166 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue197 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... by ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue144 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty62 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays53 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue140 views
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue101 views
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by ShapeBlue
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
ShapeBlue88 views

Epic Refactorings - Melbourne Cocoaheads June 2011