In this episode, Matt Machuga of Think Through Math returns to talk with Adam about design options when you find yourself wanting access to a collaborator in an Active Record or Eloquent model. They discuss the pros and cons of four specific designs, and finish off with their personal recommendations.
- Are facades and service location automatically bad?
- Are NounVerber classes anti-OO?
- Adding a layer of composition to create domain models with dependencies
- Using method injection for a temporary dependency
- Using optional parameters to improve testability
- Option 1: Facades/Service Location/Global Access
- Option 2: Moving the responsibility to a new class
- Option 3: Composing a new domain model
- Option 4a: Inject the dependency into the method
- Option 4b: Optional method injection w/global fallback