Created
December 22, 2011 12:00
-
-
Save craigw/1510069 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def bar | |
rand(10).to_s | |
end | |
end | |
# My interface is the same as Foo because I just decorate that behaviour | |
class FooDecorator | |
attr_accessor :other | |
private :other=, :other | |
def initialize other | |
self.other = other | |
end | |
def bar | |
"The number is #{other.bar}" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def bar | |
rand(10).to_s | |
end | |
end | |
class Baz | |
def baz | |
rand(100).to_s | |
end | |
end | |
# My interface is different to Foo or Baz, it provides convenient and consistent access to possibly several underlying objects | |
class FooBazPresenter | |
attr_accessor :foo, :baz | |
private :foo=, :foo, :baz=, :baz | |
def initialize foo, baz | |
self.foo = foo | |
self.baz = baz | |
end | |
def to_s | |
"Foo #{foo.bar}, Baz #{baz.bar}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment