I do need your valuable help.
A few weeks ago I developed a small program in Java.
Probably a wrong approach, but I didn't tackle the problem with UML in mind, but on the basis of a given idea I
built a fully functional piece of software which lives up to expectations.
The program itself consist of two classes and several methods.
Now I need to draw the corresponding UML class diagram and it seems a very knotty problem for me.
Since the UML class diagram aims at showing the source code dependencies between classes, I'm wondering
how I can draw a class diagram based on the following code.
.................................................................
import javax.swing.JPanel;
class WavPanel extends JPanel {
List<Byte> audioBytes;
List<Line2D.Double> lines;
public WavPanel() {
super();
setBackground(Color.black);
resetWaveform();
}
public void resetWaveform() {
audioBytes = new ArrayList<Byte>();
lines = new ArrayList<Line2D.Double>();
repaint();
}
}
................................................................
In a nutshell, the WavPanel class is an example of inheritance.
The JPanel class (part of a package) acts as a superclass.
How can I solve the problem?
My concern is that JPanel is a class which is part of a package.
Furthermore, in order to draw a good class diagram am I wrong in
thinking that maybe I had to do the UML diagram first and then write the
associated code?
The fact that I wrote several methods (instead of classes) and just a few classes,
can that be a problem with UML?
If so it would mean reengineering the entire software again.
Thanks in advance . Any help will be highly appreciated.
Yes, you should always do the planning before the programming. However, all is not lost.
You can still use JPanel in your UML, just show the inheritance (using the white diamond) for subclasses that use JPanel. I like to draw all my UML diagrams using UMLet, especially because (in the future, when you do UML first ;)) you can export your diagrams into Eclipse!
Methods and their arguments are specified inside the classes in a UML diagram. You don't really care about what each method DOES for a class diagram, just its characteristics for the most part. Focus on show the relationships between classes, even if they are libraries. Don't worry about all the individual methods in a library though...some API somewhere has probably taken care of that.
Do you need more help on UML itself? Let me know and I can add to this answer to clarify any other questions you have on UML in general, or consult this Wikipedia article on class diagrams.
You're not thinking about UML properly.
If your application works, then the fact that the UML is causing you difficulty should not be a concern.
UML is a communication notation, nothing more.
It's not a requirement to do the UML before coding. UML is not a requirement at all. Thinking is required. If creating UML helps you to think, by all means do it. But it's not required.
Your solution is simple: either import JPanel into your UML model and add inheritance to the class diagram, or create a stand-in for the sake of the diagram.
The program itself consist of two
classes and several methods.
No, the program consists of two classes that were written by you plus several core Java classes (e.g., JPanel, List, etc.) Are you suggesting that it's important to include every class in your class diagrams, even the Java core classes? I would disagree with that. Perhaps noting that your WavPanel inherits from JPanel would be useful, but I don't add java.lang.String to any UML diagrams that I create.
I wouldn't consider UML to be worth the effort for a solution that consisted of five classes or fewer. Those I can keep in my head. UML tends to help more when I have a larger problem than five classes.
Related
I had been doing some UML class diagram examples from the recent exams for my software design course, and I found one where it says:"Design a class model for a specific problem, by using MVC and STATE pattern, but no need to include getters and setters." Is this the same thing as the regular class diagram? I've been googling and I found nothing UML based by searching for class MODEL.
The model is abstract. A diagram is a view on the model. UML offers a number of different diagrams. There are mainly two categories: static and behavioral. Class diagrams fall under the static category and they show how the classes in the model are related to each other. You can create multiple class diagrams like one with all classes (assuming that you have a rather limited number of classes) and/or one per class with that in focus. Or you have sub-domains with related classes placed in one diagram. The behavioral diagrams shed light on how class instances communicate with each other at run time.
As a side note you can think of it in terms of Platon's Cave Allegory. The diagrams are the shadows of the real world projected by a fire to the wall you can see from you chained position.
"Design a class model" means: "Create one or more class diagrams that together form a consistent model".
A model in computer science is a graphical representation of (a piece of) software or of (a part of) the business domain in order to help people know or understand the subject the model represents (see wikipedia). This graphical representation may consist of one or more diagrams.
I know that I can build a Class diagram from a database E-R Diagram (tables become classes, tables properties are the classes properties...)
But I'm looking for informations (or step by step like) to create a class diagram from a use case description (or even a sequence diagram).
(All I found now is that the sequence diagram objects becomes classes and the stimuli messages methodes)
Any idea ?
I used to TA in software engineering, and both create a class diagram from a textual definition as well as create a class diagram from a sequence diagram were regular exam questions.
Creating class diagrams from a specification should be covered in your lectures since its one of the most important things to learn. This site explains the workflow quite well in my opinion.
It is important to note, that in software engineering there never is just one solution. You can tackle problems in multiple ways each with their own benefits and problems. The most important step to learning is doing it yourself, just looking at solutions won't help you.
For creating class diagrams from a sequence diagram:
Objects are instance of classes, in most sequence diagrams there is only one instance of any given class. Therefore "objects become classes" is not technically correct but the right intention.
Messages represent method calls on the receiving object, ergo you need to add these methods to the class of the receiving object.
Any communicating classes need to be associated, else they could not call their methods.
We put focus on only modelling the information you can derive from the sequence diagram, e.g. in most cases you do not know multiplicities of associations.
can somebody please explains what is a high level class diagram. As far as I know class diagram shows the association between the classes but what about high level class diagram??
Ok, I knew what this means, a Class Diagram contains many details. A high-level class diagram is a simple class diagram reflecting only initial domain knowledge
What's the context? Class diagrams in themselves are pretty "high-level", in that they only show classes and methods rather than algorithms and other implementation details. It might just be an adjective. Or, you might be looking for something more like a block-level diagram which shows components of a system and how they interact.
I often use the term "high-level", or more usually, "top-level" diagram for the very highest level class diagram I make for a system. Usually this will show as many of the most important packages as will reasonably fit, along with some classes that give the best idea of what functionality the classes in that package provide. From there I can do class diagrams of each package, and so on.
Depending on the type of system and what your supervisor want to see, you may be better off creating a component diagram.
What kind of UML diagram is this?
(source: tripod.com)
This is a class diagram, with added stereotypes
This is Class Diagram in a very abstract or initial form because all relationship are shown as Association.
Usually we start with such class diagram and then keep on refining by converting association (arrow as shown above) into more stronger relationship like generalization,composition,implementation etc.
Association is considered as weaker form of relationship between classes. So final class diagram should have fewer associations.
What is the emphasis or goal of this diagram? If it's the classes and relationships, then it's a class diagram. If it's the mapping between the classes and layers of function or responsiblity in the system, then it looks like a layer diagram. Those columns look like layers: presentation, business logic, data...
Ok now I see the problem after a good sleep :-)
It seems it is a powerpoint and not a class diagram because you can not have straight line in a class diagram. I mean you can not have 3 separators like Presentation/ objectos .......etc
This powerpoint tried to use class diagram and have added titles in order to separate 3 layers. The problem is that the class diagram is incorrect and it is not because you present it with 3 layer that it would become correct !! This is a bad understanding of what means JPA stereotypes inside a class diagram.
It looks like a Class Diagram that uses "swimlanes" on the background to facilitate some kind of MVC.
This class diagram is not correct because there is confusion between Java EE stereotypes and class names!
What are the << class module>> , << module>> stereotypes and Session, Session persistence names should be Java EE stereotypes. If it persists in the database then it is an entity! Persistence etc...can be written on attributes.
This diagram doesn't make sense!
The main advantage of scheme in this diagram is that if you use a code generator such as AndroMDA, MIA software or Blue Age, then you can then generate your database directly from the model. These tools look at stereotypes during code generation.
If you don't want to generate code from a model but prefer to let hibernate mapping do the job, then the "entity" stereotype can be written as an annotation in your java code. Then thanks to live code and model synchronization, hibernate can take the annotation and produce a mapping.
This is why stereotyping is really very important and using the wrong stereotype can be a very serious mistake!
I'm drawing some UML in which a concrete class inherits from an abstract class which defines a pure virtual method. Is it required to show this method in the concrete class as well? It's implied by inheriting from the abstract class.
Nope, you don't need to. in fact, in general, don't put any more in the UML than you must have to clarify what you're saying, unless you're (god forbid) trying to generate code from it.
The best guide I know of for UML is UML Distilled by Martin Fowler.
The funny thing about UML is that it has a pretty loose and varied definition. Most things that are called UML are actually not much more that block diagrams. There is a lot of ambiguity in any UML implementation.
I would say that if you are doing this for a presentation or architectural diagram, you can take care of a lot of the possible ambiguity with 'words'. If you will be generating code from it using some application, you should check the docs of that particular application.
It's implied and in fact, many CASE tools would show you the inherited method as part of the list of the methods of the subclass when clicking on the class at looking at its properties (and some CASE tools even have the option of showing also the inherited methods in the diagram)