How to show Dependency Injection on a UML class diagram?

前端 未结 3 688
迷失自我
迷失自我 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:31

    Martin Fowler shows it like this:

    DI UML

    0 讨论(0)
  • 2021-02-02 09:35

    You display class dependencies by using a dashed line with a pointed arrow that points from the client model element to the supplier model element.

    I think that how you provide the dependencies to the client is irrelevent at the UML level.

    0 讨论(0)
  • 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
    0 讨论(0)
提交回复
热议问题