Nelz458
Nelz458

Reputation: 9

UML and Code Relationship

I understand that the main goal of UML is to communicate. UML intends to provide a design of a system and Code really is the actual building block of the system.

My question is if code an uml are suppose to directly mirror each other. Let me explain:

package ShowTimesFrUSA;

I wanted to present my program with designs of UML with a package Diagram. However I already divided my classes into different packages differently from the way it is coded. Packages:UI (AWT and Swing) , Controllers, Moviemonitor, MovieService, USAmovies <<server>>

I just want to show the dependencies between the class groups in my code as part of the requirements for this presentation and the package diagram is really good for that. But I am unsure if the packages in the model should directly mirror the way packages are coded in java?

Upvotes: 0

Views: 221

Answers (2)

Miguel Cruz
Miguel Cruz

Reputation: 11

When you start thinking about a solution to your problem, and draw a class diagram to communicate, you are indeed designing the classes you will need in your program at the business logic level. At this level, UML and code should be in sync. Of course, the code will have more information, such as complete implemented methods. At the UI code level, usually UML classes do not help or communicate much.

Upvotes: 0

Michael Borgwardt
Michael Borgwardt

Reputation: 346260

I am unsure if the packages in the model should directly mirror the way packages are coded in java?

Definitely yes. That's what UML packages are meant to represent. How would you think of code that is one huge "god object" class but the author models it as several distinct classes in UML?

If you divide your code into packages conceptually, why would you not want that to be reflected in the code using a mechanism intended for that purpose?

Besides, it sounds like you're currently not using a package statement at all, i.e. your code lives in the nameless default package. That's a bad practice for all but throwaway toy code because it causes several problems. For one thing, it's impossible to use your code from other code that does use packages.

I think the underlying problem may be that you are misunderstanding UML packages. They are not really meant as an abstract marker to show that a class is e.g. a UI class or a Controller. That is what UML stereotypes are for.

Upvotes: 2

Related Questions