开发者

Grasp creator vs. dependency Injection

开发者 https://www.devze.com 2023-03-06 19:00 出处:网络
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 circumstance

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号