required interface vs interface realization vs <

2019-06-25 06:26发布

As the title suggest what is the difference between the three and when should one use one of the three instead of the other two? The internet is filled with their definition but i couldn't find any text or explanation on when and where to use required interface or the <<use>> dependency.

标签: interface uml
2条回答
冷血范
2楼-- · 2019-06-25 06:35

There are only two cases in fact: realize/use on the one hand, and provided/required on the other. They essentially describe the same thing, but with different emphasis.

With realize/use you draw visible relationships from the class (or component, as in my examples below) to the interface, and thus show the interface and its operations in the diagram.

realize/use

You could, of course, split that into two different diagrams.

With provided/required, on the other hand, the interface is only shown as lollipops so you can't see the operations. But you can draw visible relationships (usually "assembly") between the lollipops.

provided/required

I'd say that realize/use is more appropriate if you want to show who implements what. Provided/required is more appropriate if you want to focus more on interactions between parts.

查看更多
地球回转人心会变
3楼-- · 2019-06-25 06:40

A required interface is usually shown as socket. It means that in order to have the class working it needs at runtime a counterpart with a lollipop. This counterpart in turn offers the interface via a lollipop. To decouple class and interface definition you put the interface in a stereotyped class and draw a realization from the providing class to the interface. Vice versa you draw a dependency from the requiring class to the interface. Whether you stereotype the dependency with <<use>> is more a matter of taste.

enter image description here

as described above and as alternate representation: enter image description here

查看更多
登录 后发表回答