开发者

UML: How do I do this...?

Several questions about UML: Do I include the main class in my UML diagram? If I do include it, and it instantiates objects, do I draw an empty arrow (such as ->) from my main class to the classes it instantiates? When do I use the diamond vs. the arrow?

I'm just curious about those 3 things... While an article would also be very helpful, could s开发者_StackOverflow中文版omeone address those three questions?

Thank you so much.


Do I include the main class in my UML diagram?

There are many types of UML diagrams, but I suspect here you mean a class diagram. The answer to your question is literally: if you want to. The beauty of UML is that you can make many diagrams, that vary in detail. Some diagrams will show just a few classes, some many. The idea is that you diagram different parts of the system, at different views, for different audiences. Diagram as much or as little as you like. If you are making a very small application with just a few classes, then it probably will make sense to show the main class. Give it a stereotype or use a comment that identifies it as a "main application class."

If I do include it, and it instantiates objects, do I draw an empty arrow (such as ->) from my main class to the classes it instantiates?

You certainly may, again "if you want to," There will be a dependency here in a way: the main class "depends on" the other classes because it uses them somehow. That is, if main class A instantiates objects of class B, then class A needs class B to compile, so you may show this as a dependency if you wish.

When do I use the diamond vs. the arrow?

The diamond shows aggregation or composition and is used as follows: if class A has a field of class B, then an arrow from A to B with a diamond on the A side is called for. The "plain arrow" just shows a relatively unspecificed dependency. You can use it from class A to class B when class A uses, somehow class B. Perhaps a method of class A uses an instance of class B as a local variable. No containment (composition or aggregation) of a B in an A is implied with the plain dependency.


It seems that you are not an UML expert but this is not a problem. What I would recommend is to simply reverse engineer your code into class diagrams and then add your own notes inside a yellow rectangle having a connector linked to what you consider important. You will get a graphical representation of your code and would be able to add value comments without having real UML knowledge.

UML class diagram is really simple and can cover all needs of a project. If you don't know UML then just do class diagram by reversing your code and enjoy :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜