Skip to content

Instantly share code, notes, and snippets.

@jwilger
Created September 15, 2012 21:34
Show Gist options
  • Save jwilger/3729891 to your computer and use it in GitHub Desktop.
Save jwilger/3729891 to your computer and use it in GitHub Desktop.
Quick API design poll
# A) Instantiate Connection object directly, have it know whether it
# needs to use a "test mode" implementation internally.
my_api = MyAPI::Connection.new(:mode => :test)
# B) Directly instantiate a "test mode" connection object. In
# production, a call to `MyAPI::Connection.new` would be used instead.
my_api = MyAPI::TestConnection.new
# C) The MyAPI module has a factory method that knows whether to return
# a `Connection` or a `TestConnection` (or a `Connection` in test
# mode?).
my_api = MyAPI.connect(:mode => :test)
# D) The MyAPI module has a factory method that returns a
# `TestConnection`. It would have a similar `#connect` method that
# returns a `Connection`.
my_api = MyAPI.connect_test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment