Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Refactoring to avoid tight coupling #7

Open
wants to merge 3 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

andyw8 commented May 12, 2012

This code demonstrates how BeerDetailsController can be injected as a dependency into BeerListController. This avoids the awkward chained call of BeerDetailsController via UIApplication (which violates the Law Of Demeter).

@andyw8 andyw8 Refactoring to avoid tight coupling
I've changed this to demonstrate how BeerDetailsController can be injected as a dependency into BeerListController. This avoids the awkward chained call via UIApplication (which violates the Law Of Demeter).
d874f69

@lrz lrz commented on an outdated diff May 12, 2012

Beers/app/beer_list_controller.rb
@@ -1,6 +1,7 @@
class BeerListController < UITableViewController
- def init
- if super
+ def init(beer_details_controller)
@lrz

lrz May 12, 2012

Owner

Wouldn't it be clearer to define initWithDetailsController() instead?

Contributor

andyw8 commented May 13, 2012

I agree initWithDetailsController would be a better name. I tried renaming it but it fails with:

"Terminating app due to uncaught exception 'ArgumentError',
reason: 'beer_list_controller.rb:4:in `initWithDetailsController:':
wrong number of arguments (0 for 1) (ArgumentError)"

Not sure how to deal that?

Owner

lrz commented May 13, 2012

Perhaps the 'super' call is the cause of the exception here? I would try replacing 'super' with 'init'.

Contributor

andyw8 commented May 13, 2012

That's seems a good solution.

Owner

lrz commented May 13, 2012

Now I think BeerMapController should also be similarly updated? (Sorry just realized this now!).

Contributor

andyw8 commented May 14, 2012

Hmm, that seems to break the the tab bar title/icon for some reason.

@alloy alloy commented on the diff Nov 4, 2013

Beers/app/beer_list_controller.rb
@@ -1,6 +1,7 @@
class BeerListController < UITableViewController
- def init
- if super
+ def initWithDetailsController(beer_details_controller)
+ @beer_details_controller = beer_details_controller
@alloy

alloy Nov 4, 2013

Owner

Storing instance variables is not supposed to be done until after the if init check.

Owner

alloy commented Nov 4, 2013

Is the reason that the detail controller is being cached so that the webview doesn’t have to be loaded every time? Can we just instantiate it on demand every time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment