Is GRASP Creator a complete contradiction to Dependency Injection?
If it is not, please explain why.
It is not a Contradiction, however they are both used in different circumstances.
You are more likely to use Creator in the Domain Layer, and use Dependency Injection or Factories in your Application Service Layers (logging service, controller factories, authentication services, etc. depending on your platform) and Domain Service / Data Access Layers (Repositories, Data Mappers, Data Gateways, etc.).
This distinction is made clear by Larman in "Applying UML and Patterns" (where GRASP Patterns/Principles are defined) stating that Creator is contraindicated in instances where reuse of recycled instances are important for performance or the decision as to which class among a family needs to be instantiated. In these instances, instantiation is better left relegated to Factory, Abstract Factory, or DI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With