Created
September 22, 2013 10:24
-
-
Save DivineDominion/6658694 to your computer and use it in GitHub Desktop.
Repository in Ruby according to Eric Evans (2006): Domain-Driven Design. Tackling complexity in the heart of software, Upper Saddle River, NJ: Addison-Wesley.
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 InMemoryStrategy | |
def matching(criteria) | |
results = [] | |
domain_objects.each do |object| | |
results << object if criteria.satisfied_by?(object) | |
end | |
end | |
end |
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 RelationalDatabaseStrategy | |
def matching(criteria) | |
query = Query.new # --> QueryObject pattern | |
query.add_criteria(criteria) | |
return query.execute | |
end | |
end |
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
# Repository with pluggable strategy. | |
# Strategy can be replaced during tests, too. | |
class Repository | |
def matching(criteria) | |
repository_strategy.matching(criteria) | |
end | |
private | |
def repository_strategy | |
@repository_strategy ||= InMemoryStrategy.new | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment