Not exactly following what is depicted on project UML diagrams - uml

This has been confusing me for quite some time. I have an app which is already done, but since the client is looking for a detailed documentation of it, I now have to create diagrams. The point where I get so confused is, whenever I make the diagrams, it just seems that the diagrams are not as exactly the same as what my coding looks like.
For example, on my class diagram, I have a class called 'announcements' and under that class is a method which getAnnouncements(). But in actual coding, you'll never find a method that is named getAnnoucements() since I opted to not create a method for it and instead put the codes directly on the main class. I know it's not a good coding practice, but what if? So these are my questions: Do I really have to follow what is on the class diagram? Or since I'm using reverse engineering, do I have to follow what is on my code and make diagrams of it?

If you're making a documentation and you're making a UML at the code level follow whatever you actually have in the code.
The benefit of this approach will be that
you really have diagrams similar to your code
you (and your client) will be able to recognize parts of poor code (i.e. not following various standards) - like those you describe. It gives chance to improve it in the future
The drawback is that you might need to correct the automatically generated diagram. Each time you generate it.

Related

How can I generate a UML diagram without a GUI

I'm trying to create a UML diagram from the command line without preexisting code.
Eventually I'll write code in C++/Java, but I need to create a diagram first.
I'm thinking of a header-like file, which could be read and could generate a diagram.
Of course, I could just create a header and generate it. However, I'm not supposed to write any code until I've submitted my diagram (I'd also just like to have an efficient way to do this for the future).
UML does not require application to draw. On the contrary one of the main usages of UML is to model the application that you're going to build to understand it better and make a better code as a result.
You also don't use application you create to draw UML diagram. You can use any application that supports UML modelling. Simple Google search or visit on Wikipedia will give you tons of options. You may even take a sheet of paper and a pencil. I've seen a course of UML, where participants did not use computers. They were supposed to learn UML, not tools that allow to draw it.
Finally (answering the question stated in the question topic), UML is in no way limited to model only graphical applications. Static structure and dynamic behaviour of the system exists regardless if user communicates with it through a GUI or command line.
Are you sure you understood the reason why you are supposed to make a UML diagram or do you disagree with that reason? What I can definitely suggest is to find a good book about IT business analysis using UML. This site is not to recommend specific books, but again Google will be your friend here.
As according to the comment the goal is to actually generate a UML class diagram from text let me add a second part of answer
First disclaimer. In general SO is not a place to ask for tools and that question is brushing it. Let me make my answer more generic though.
UML is in general graphical language so technically what you need is something that will parse text version of your "diagram" into a nice picture.
Most if not all tools keep UML in some textual format, be it XMI or some internal legacy solution. The problem with that is that the format is usually pretty complex.
There are some tools that are intended to "draw" diagram by typing text and that's probably something that would suit you best. In general I definitely prefer "normal" GUI but if you insist yuml.me has a nice and easy to understand textual layer based on which it generates really cool diagrams. You may expect you will find others as well, so as usually, ask uncle Google. As suggested by Thomas Kilian in a comment, PlantUML is another example as it can work without GUI and "is an open-source tool allowing users to create UML diagrams from a plain text language." (quote after Wikipedia)

What is the use of UML in day today life?

I don't have a programming job. But I do code (using functional programming and OOP) from time to time, in order to make many repetitive tasks, that I perform in the software I use, simple: extract data from a simulation and dump it into an excel file, read data from an excel file and use that data to manipulate my simulation, etc.
I can manage this pretty well without using UML. But what I want to know is: for someone who doesn't code for a living, yet uses code to make life simpler and save time, how important is using UML (I do understand that I cannot use it for functional programming)? What are the practical benefits? How can I write better code by using UML? I know it's not a substitute for a programming language .. as in I cannot use it as a programming language. But what I was also hoping to understand was how can I use it before I actually begin to write OOP code?
Unlike other answers suggest I believe that UML is not only beneficial when you work with a team of developers, also when you work on a project on your own you can benefit by using UML.
In my opinion the true benefit of UML is that you are forced to think before you act. Of course you can always directly start programming when starting a new project, but (most certainly for larger projects) it is better to think about your design.
By creating complete UML models you will notice that you need to think about your software (what does the user needs to be able to do with my software? How will the software react? etc. etc.). Due to this whole process I believe that by the time you will start coding, you will already have such good understanding on the structure of your program that you will be able to code your project better and faster.
Concluding I think UML is all about doing it right the first time.
Next to this, you will always have proper documentation on your code. This makes it more easy to maintain.
Not very sure what you mean by day to day life but UML helps in:
The communication of the desired structure and behaviour of a system between analysts, architects, developers, stakeholders and
users.
The visualisation and control of system architecture.
Promote a deeper understanding of the system, exposing opportunities for simplification and re-use.
Manage risk.
When working in a team, you first create a UML. That way you know which classes have to be made and you can divide the working, knowing everyone will use the names on the UML with the right connections between classes. (Inheritance, composition,..)
It's an abstract version of a program and it's very important. Ofcourse, if you're on your own you don't 'need' to use it, but it might make life easier. If the task takes long, create the UML beforehand so you don't loose track of what you're doing plus it helps you see design patterns. :)
In addition to the other mentioned use cases of UML models, the most efficient use case for a UML model is when it is used to generate other models or text (code).
For instance you can generate java classes from a UML class diagram.
Search for MDA (Model Driven Architecture) or MDSD (Model Driven Software Design).
If you are looking for a tool to support generating code/text from UML models then take a look at the Acceleo Project.

How to resize my UML class diagram on MS Visio'07

How do i resize the class diagram in Visio? My operations have many parameters so the class diagram becomes too long. I need to resize the height of it,how can i do that?
Well..
The short answer is
DO NOT RESIZE IT.
If still want to resize
Check
--> http://support.microsoft.com/kb/264676
--> http://social.technet.microsoft.com/Forums/en-US/visiogeneral/thread/4a8a9688-7d11-466f-b809-828d6e9b4c11/ [Emely16 answer]
And Here is the LONG ANSWER:
If you do a reverse engineering to your code [ from code to digram] to understand code base better
Well visual representation like UML also shows some "problems"
visually. First it should give you a code smell about "something is
wrong with my code" [ it may show a real problem or just an false
alarm] Check it and ask yourself "Why i have so many parameters in my
methods".
If you are designing your system [ not write the code yet ]
You are at wrong direction. UML is a visual thinking tool. Change your model-class.
But do not try to model every part of your software details with UML
before coding.Use UML for hard and tricky parts to explore alternative design, to better understand system that you will code.Only the working code is the real model.
And As A general Modeling Advice [ Short Answer ]
Whether you are doing reverse engineering or use UML to explore difficult part of your design
To make your diagrams simple, you may choose NOT to show method
parameters : Even sometimes you may cose not to show also methods and attributes even some classes also.This is OK.
AS A COMMON SENSE RULE
Ask yourself, if I show method parameters, what benefit will I get?
HUMANS ARE IRRATIONAL
You may find yourself in a crazy working enviroment where QA team or Boss want so.
Explain them with a common sense why this is bad.
If they insist on it, and you have no choice, ask them to buy a UML modeling tools which are more easy to use. And give them complicated and unusefull diagrams since they want it. :-)

StarUML in generating C++ code

I'm new to UML and I have written a Sequence diagram for a Voucher User Interface, it is a small pet project I'm doing to learn UML. I have written a decent Sequence Diagram in StarUML and now I would like to generate the C++ code, the step is very simple I just go to Tools/C++/Generate Code... But there I face a problem, which you can understand from the screen captures below. I tried various places but I could not find any help, anyone experienced in StarUML who could help me go further?
Haven't used starUML for a while so things may have changed. But:
Last time I looked, it didn't provide templates for behavioural code generation. The only codegen templates were for static structure (classes, attributes, packages). If that's still the case then I suspect the empty panel arises from it not finding any suitable model elements to generate code for. i.e. your Sequence Diagram package doesn't have any classes in it.
You might be able to work it out by looking at the codegen templates; they should be in
<STARUML_INSTALL_PATH>\modules\staruml-generator\templates
hth.
I just tried to generate the code from start uml.
With Version 5.0.3.1570. It works well.
I got the diagram instantly.
One issue, it actually did not generate the composition / aggregation stuff but, then, I did that manually.
Since its propitiatory for my organization, I cannot revel but, sequence is exactly the same as of yours.
I choose Design model & then gave file path in dialog box.

UML and documenting long methods

I am using UML to document parts of an older c++ program. It's only a portion of the code, but documenting it has made me insane since even this process is quite large. So far I have used class diagrams for the relevant code and some activity and sequence where necessary.
My question is I feel what I have done so far is good for the overall documentation but I want to get down to the dirty details of a few methods and one of them is 202 lines long, what should I use for this? An activity diagram or sequence?
I am using Visio for the UML documentation.
Thanks.
A rule of thumb might be that if it seems like there are multiple agents handing off flow between each other, use sequence; otherwise, activity. In a single function, activity is probably best - but not necessarily.
Try to imagine what it's going to end up looking like, put yourself in your ignorant reader's shoes, and think about which will tell the story better.
Is splitting up the function an option?
The question is: Do you want to describe the process or the interactions between objects that those few methods are executing? The process can be broken down into activities which are performed, their composition and data flow. Interactions are comprised of messages sent between objects.
Well,
Short answer is:
If you want to document an algorithm (that is used by one of your system object^s method): Use Activity diagrams.
Long Answer:
For my experience UML documentations are the worst ones.
People generally use Uml Tools which automaticly reverse engineer code to Uml (generally class diagrams, and sometimes sequence diagrams) and diagrams that are automatically generated are generally has many details and sometimes nonsense.
As an advice "Comments your code properly" and use tools like Doxygen. They are better for Code Documentation.
But you can use UML for Software Architect Document.[SAD]. Craig Larman has nice section and example of it at his books about Documenting Architecture
Motivation: Why Create a SAD?
When someone joins the development team, it's useful if the project coach can say, "Welcome to the NextGen project! Please go to the project website and read the ten page SAD in order to get an introduction to the big ideas." And later, during a subsequent release, when new people work on the system, a SAD can be a learning aid to speed their comprehension.
Therefore, it should be written with
this audience and goal in mind: What
do I need to say (and draw in the UML)
that will quickly help someone
understand the major ideas in this
system? [ Applying UML and Patterns Third Edition By Craig Larman ] [Chapter 39. Documenting Architecture: UML & the N+1 View Model]

Resources