Grasp creator vs. dependency Injection
Is GRASP Creator a complete contra开发者_StackOverflowdiction 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.
精彩评论