More Context IoC

Thanks go to Ade for providing me with many fun links and this insightful comment:

If you find yourself seeing duplicated signatures containing lots of arguments to constructors it usually indicates a missing abstraction which would bring together all those dependencies. So instead of having:
public FootBallGame(RuleValidator rv, TimeKeeper tk, RuleEnforcer er, WhistleBlower wb, …)

you would have:
public FootBallGame(Referee r)

and the referee would then play all those roles.

This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to More Context IoC

  1. anonymous says:

    The thing though is that really is not IoC. It is more like good class design. Sure it may help in IoC, but I do not agree we creating objects to support a design style…your design style should be flexible around your objects

  2. sirenian says:

    I know it’s not pure IoC. I was looking for something which lay somewhere between true IoC and “Contextual IoC”, and most particularly, something which worked better than calling a batch of common constructor dependencies “context” or “toolbox”. If I was coding this I certainly wouldn’t start with a Referee – but given enough changes to the FootBallGame, I might refactor and add one.

  3. anonymous says:

    None of this is IOC. It’s just dependency injection or object orientation if you’re old-fashioned.

    IOC is about your code being called by the framework you’re using. See John “Gang Of Four” Vlisside’s book from 1998 (http://www.amazon.co.uk/exec/obidos/ASIN/0201432935/qid=1112976979/sr=8-2/ref=sr_8_xs_ap_i2_xgl/202-7542138-1011867) for a good definition that talks about IOC as the concept that distinguishes libraries from frameworks. I really wish people wouldn’t hi-jack perfectly meaninful terms. Not least because I sound like a middle-aged curmodgeon when I try to get people to avoid reinventing new names for old ideas.

    –ade

  4. sirenian says:

    I am reprimanded and will add this book to my reading list.

    (See my userinfo to work out how likely it is that I’ll get around to reading it, but thank you very much for the shortened version!)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s