Skip to content

Instantly share code, notes, and snippets.

@garethrees
Last active December 18, 2015 09:59
Show Gist options
  • Save garethrees/5765558 to your computer and use it in GitHub Desktop.
Save garethrees/5765558 to your computer and use it in GitHub Desktop.
Removing feature envy
class WebServer
def start
Application.new().run
end
end
class Application
def run ; end
end
server = WebServer.new
server.start
# What if we want to use the server to run a different application?
class BetterServer
def initialize(a=Application.new)
@app = a
end
def start
@app.run
end
end
class BetterApplication
def run
# better, faster
end
end
app = BetterApplication.new
server = BetterServer.new(app)
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment