Question

Is GRASP Creator a complete contradiction to Dependency Injection?

If it is not, please explain why.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top