-
-
Save iafonov/1145904 to your computer and use it in GitHub Desktop.
DCI and Aggregate
This file contains 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 Human | |
attr_accessor :address | |
end | |
class Address | |
def to_s | |
"City: #{@city}" | |
end | |
private | |
def initialize(city) | |
@city = city | |
end | |
end | |
module Policeman | |
has_many :coworkers, :as => :humans, :in_role => :policeman | |
has_many :caught_thefts, :as => :humans, :in_role => :thieft | |
def check_address(address) | |
# do some stuff | |
end | |
def notify_coworkers | |
coworkers.map &:search_neighborhood | |
end | |
private | |
def search_neighborhood | |
# do | |
end | |
end | |
module Thief | |
has_many :nigger_friends, :as => :humans, :in_role => :thief | |
end | |
module FakeAddress | |
def to_s | |
"City: LA" | |
end | |
end | |
class ArrestContext | |
def execute | |
@policeman.check_address @thief.address.to_s | |
@policeman.notify_coworkers | |
end | |
private | |
def initialize(policeman, thief) # imho this method looks ultra-ugly | |
@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