Skip to content

Instantly share code, notes, and snippets.

@MitinPavel
Created May 29, 2011 13:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MitinPavel/997773 to your computer and use it in GitHub Desktop.
Save MitinPavel/997773 to your computer and use it in GitHub Desktop.
DCI and Aggregate
class Human
attr_accessor :address
end
class Address
def to_s
"City: #{@city}"
end
private
def initialize(city)
@city = city
end
end
module Policeman
def check_address(address)
# do some stuff
end
end
module Thief
end
module FakeAddress
def to_s
"City: LA"
end
end
class ArrestContext
def execute
@policeman.check_address @thief.address.to_s
end
private
def initialize(policeman, thief)
@policeman = policeman
@policeman.extend Policeman
@thief = thief
@thief.extend Thief
@thief.address.extend FakeAddress
end
end
policeman, thief = Human.new, Human.new
thief.address = Address.new 'NY'
context = ArrestContext.new policeman, thief
context.execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment