required interface vs interface realization vs <<use>> dependency

≡放荡痞女 提交于 2019-12-10 15:14:55

问题


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.


回答1:


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.

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.

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.




回答2:


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.

as described above and as alternate representation:



来源:https://stackoverflow.com/questions/28686194/required-interface-vs-interface-realization-vs-use-dependency

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!