Skip to content

Instantly share code, notes, and snippets.

@rewinfrey
Created February 13, 2015 23:07
Show Gist options
  • Save rewinfrey/5a70d8b2204032ac0d7d to your computer and use it in GitHub Desktop.
Save rewinfrey/5a70d8b2204032ac0d7d to your computer and use it in GitHub Desktop.
Example Strategy Factory
# this would be called in the controller,
# whose return value is the Strategy class
class CandidateJobDocumentStrategyFactory
def self.strategy_for(document_type)
case document_type
when :resume then resume_strategy
when :cover_letter then cover_letter_strategy
when :application then application_strategy
end
end
def self.resume_strategy
ResumeStrategy
end
def self.cover_letter_strategy
CoverLetterStrategy
end
def self.application_strategy
ApplicationStrategy
end
class ResumeStrategy
def self.execute(candidate_job, resume)
# business logic of associating the resume to the candidate_job
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment