Skip to content

Instantly share code, notes, and snippets.

@steida
Created January 9, 2012 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save steida/1584972 to your computer and use it in GitHub Desktop.
Save steida/1584972 to your computer and use it in GitHub Desktop.
# Dependency injetion example.
class House
# We are asking for things in contructor.
constructor: (kitchen) ->
@kitchen = kitchen
# Service locator antipattern example.
class House
constructor: ->
# our class is looking for kitchen
@kitchen = new Kitchen
# another point of view
# house is frozen
class House
constructor: ->
@kitchen = new Kitchen
# now house can have any kitchen
class House
constructor: (kitchen) ->
@kitchen = kitchen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment