Skip to content

Instantly share code, notes, and snippets.

@DivineDominion
Created September 22, 2013 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DivineDominion/6658694 to your computer and use it in GitHub Desktop.
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.
class InMemoryStrategy
def matching(criteria)
results = []
domain_objects.each do |object|
results << object if criteria.satisfied_by?(object)
end
end
end
class RelationalDatabaseStrategy
def matching(criteria)
query = Query.new # --> QueryObject pattern
query.add_criteria(criteria)
return query.execute
end
end
# 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