Created
October 13, 2012 15:23
-
-
Save nicholasjhenry/3884978 to your computer and use it in GitHub Desktop.
Thoughts on the birthday greeting kata
This file contains hidden or 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
| # As seen from the example below, you could imagine a Rails application | |
| # "depending" on this application logic. Controllers would act as the 'main' | |
| # instantiating collaborators to inject into the service (aka use case). | |
| # "Note that the collaborators of the birthdayService objects are injected in | |
| # it. Ideally domain code should never use the new operator. The new operator is | |
| # called from outside the domain code, to set up an aggregate of objects that | |
| # collaborate together." - http://matteo.vaccari.name/blog/archives/154 | |
| class BirthdayService | |
| def initialize(employee_repository, email_service) | |
| @employee_repository, @email_service = employee_repository, email_service | |
| end | |
| def send_greeting(date) | |
| birthday_people(date).each do |birthday_person| | |
| email_service.deliver_birthday_greeting(birthday_person) | |
| end | |
| end | |
| private | |
| def birthday_people(date) | |
| @employee_repository.find_all_by_date_of_birth(date) | |
| end | |
| end | |
| employee_repository = EmployeeFileRepository.new # or Employee < ActiveRecord::Base | |
| email_service = ??? | |
| birthday_service = BirthdayService.new(employee_repository, email_service) | |
| birthday_service.send_greeting(Date.today) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment