Representing swing components in UML class diagram

2020-07-14 05:45发布

I have some questions regarding the representation of the gui objects in uml class diagrams.

For example if a have a class which extends the JFrame, then i will design the UML class diagram with the inheritance symbol, but in the JFrame, i do not need to write down all of it's class variables and methods, but only those whose my class will use right??

Second how will i represent that my class will use a specific layout manager? With the association symbol, i quess but i am not sure.


Say for example I have a package named gr.mydomain.exampleproject, and I have a class extending the JFrame.

Is the following approach correct or do I need to put the JFrame in a separate package (javax.swing)?

enter image description here

1条回答
疯言疯语
2楼-- · 2020-07-14 06:37

Yes, you must draw the inheritance symbol to the JFrame class, but leave the JFrame class empty, don't put any fields or methods in it. Everybody knows or can look at the API to see what JFrame contains. Besides, you would fill up the space with the multitude of methods present in JFrame.

Do it like this:

UML screenshot

As for layout managers: I believe the dependency relationship is the correct one in this situation. The association relationship would be correct if you would call methods on the layout manager's class. But you're probably just doing something like frame.setLayout (new LayoutManagerClass ()); (a.k.a. just creating the object). In this case, it's a dependency relationship.

查看更多
登录 后发表回答