How to show Dependency Injection on a UML class diagram?

前端 未结 3 757
迷失自我
迷失自我 2021-02-02 09:01

How do I show Dependency Injection of an object or class in a UML class diagram?

3条回答
  •  眼角桃花
    2021-02-02 09:36

    First of all, UML and DI are very much orthogonal concepts:

    • UML concerns itself with describing interactions, relationships and dependencies between concrete entities.
    • DI describes how dependencies are to be resolved.

    Thus, UML diagrams don't really have a mechanism to describe DI. However, I'm sure if DI is involved, you would see certain patterns evolve, including (but not limited to):

    • at least two entities per dependency, that is (1) the interface and (2) at least one concrete implementation
    • functions/methods that take in dependency interfaces, but (usually) no functions/methods that take in implementations of dependency implementations
    • one or multiple entities to represent the injection mechanism itself

提交回复
热议问题