Class diagram drawn from Use case description - uml

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.

Related

At a high level is it unreasonable to expect that the interface of classes in a sequence diagram look like their counterparts in the class diagram?

The picture is taken from the book "UML # Classroom". The text says "the registration is via e-mail, that is, asynchronous".
In actuality, I believe, there would be no "Student" and "Professor" objects involved in the process. Rather an interface, a call to a mail server and in general, nothing that would tell the viewer of the diagram what is really going on.
That makes sense to me because it has an illustrative purpose. The methods of the classes in the sequence diagram would only resemble the methods in a class diagram at a low level.
If I am tasked with a high level view of class diagram and high level sequence diagrams of a particular interaction, if I am then asked why the classes of the class diagram don't have any of the methods of the sequence diagram, am I right to say that they simply don't have to?
Should I reach a compromise with the sequence diagram wherein I try to make the calls similar to what will be going on in the program?
The methods of the classes in the sequence diagram would only resemble the methods in a class diagram at a low level.
Not necessary, all depends on the goal of the sequence diagram, you can have classes at design level (may be allowing to generate code) but having them in a sequence diagram giving a semantic (high) level. You can also show these classes in class/package/... diagrams without low detail so not at design level.
The only rule is to have diagram saying something useful, and following UML specification of course. Do not forget UML is not a method but a language, it does not indicate how it must be used.
Remark you can put note in a diagram to help saying explicitly its level/goal in case you are afraid it is confusing because not 100% limited/dedicated to design even using classes part of the design.
if I am then asked why the classes of the class diagram don't have any of the methods of the sequence diagram, am I right to say that they simply don't have to?
yes, because the goal is not necessary to show a sequence of calls but for instance a higher level.
Should I reach a compromise with the sequence diagram wherein I try to make the calls similar to what will be going on in the program?
Of course you can do too.
Notice a sequence diagram (so in fact an interaction) has limited features, while for instance an activity allows to model a behavior in detail without the same limitations.

Is the class diagram same thing as class model?

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.

Non-UML diagrams to show objects and their creation

I am trying to understand new piece of project. I am drawing UML class diagrams, but there is something missing for me in these diagrams: the creation of objects. What a traditional UML diagram can depict is how these classes are related to each other and how instances of these classes are related to other objects of other classes, but that is in the moment when they are already created. Sometimes it is not that obvious who creates who, sometimes it is totally misleading. For example objects of class A may create object of class B, but that A object just returns this B object and gives it to somebody else and doesn't hold any reference to it. And sometimes it holds (a reference or pointer). Sometimes it matters for the reader. So in fact there are two types (pieces) of information: holding and creating. I came up with my own way of visualizing this, but maybe there is something standard here? What do you think? And I don't have UML Object diagram in mind, that is not something very helpful when reading C++ or Java code and trying to understand the relation of classes and objects. And not sequence diagram also, that's a different kind of beast.
If you want to stick to class diagrams, you can use the «create» usage dependency from UML Standard Profile (chapter 22 of UML 2.5 specs).
«Create» | Usage | A usage dependency denoting that the client classifier creates instances
of the supplier classifier.
So e.g. here A creates an instance of B, and C just has a reference to B.
A type of UML diagrams show only one particular view of your system by abstracting the other aspects of a system. For example, a class diagram shows only the static aspect of the system, but not the dynamic behavior such as:
At what time an object was created
The central ideas of modeling a system is trying to deal with (or focus on) an aspect at a time, and at the same time to eliminate the complexity by forget about the other aspects of a system.
In this case, "creating an object at a particular time by who (another object)" should be dealt with behavior view, thus, we can use a sequence diagram to modeling the dynamic behavior:
You can see the Dimension of a sequence diagram in the Figure:
Horzontally, Objects Lifecycle
Vertically, Time
You might then be interested, how I can relate these models together? Will there be any inconsistencies among them? Right! if you are puzzling about this, you are in the right track!
Look! models are inter-connected each other, take an example, you can create a use case, and a use case can be detailed with a number of scenarios, then.. each scenario can be modeled by a sequence diagram, and the sequence diagram giving you the hints of what objects (and what operations and attributes in it) you need to build your systems, right?

Differences between a conceptual UML class diagram and an ERD?

If I create a conceptual class diagram such that each class captures 'name' and 'attributes' but not 'operations', have I not basically created what would be otherwise considered an ERD? I'm trying to gain an understanding of what the differences are between creating a conceptual class diagram as I have described versus calling it a ERD? If these are still two different animals, can somebody please explain what the differences are?
The class diagram contains just the classes in your object model with eventual links/relationships connecting diagram elements. However those links don't necessarily correspond to physical relationships like in an ERD diagram, but instead they represent logical connections.
The class diagram is just the object model of your application and does not contain any persistence-specific information. When you think about the class diagram forget about the database or any other storage you may use.
The ERD diagram on the other side, is a persistence-specific diagram which display the entities (tables) existing in a (most often) relational database. It also displays the physical relations (and cardinalities) between those tables and all other database-specific information. The ERD diagram can sometimes look similar to the class diagram, but that doesn't mean is the same as a class diagram.
There´s little difference in the expressiveness of both (if we just focus on the attributes, classes and associations part) if you use Extended Entity Relationship diagrams (the most common case nowadays)
True, they look very different at the graphical level since they use different symbols for the elements but the "semantics" are quite similar. They both allow inheritance (again, I´m talking about EER), n-ary associations, association classes, ...
The ER diagrams I've seen (most frequently ERWin IE notation) have focused on the design for a database. They are concerned with primary keys, foreign keys, have unnamed relationships, and usually have no generalization / specialization.
A good UML conceptual class diagram, on the other hand, is not concerned with keys, reflects the problem domain, and has association-end properties that at least hint at the semantics of why things are related. This helps communicate the domain down to more junior developers so they don't have to guess.
It depends on the situation where you may not like to do the ER-D. But imagine if you have a seperate data layer where the data logic is handled. In this case many details of data shall not be shared with the application layer. And you class diagram shall not go beyond the application layer. I must stress that both the diagrams are not equal. And there are situations where you need to do both, mainly in multi-tier architecture, and there are situations where you may be able to just use class diagram; e.g. single-tier application.
I strongly advocate the view that class diagram doesn't abrogate the E-R diagram.
Design class diagrams are made from conceptual model and collaboration diagrams.
Design class diagrams include:
Classes, associations and attributes
Methods
Types of attributes
Navigability
Dependencies
IMO In Simple terms
Class diagram depicts the details of how will the system work.
ER diagram depicts how the system persists 'state' as a blue print.
Goal:
Detail out state and behavior of the components(classes) of the system.
Design 'efficient', flexile system(less coupling and more cohesion) using Solid principles.
Goal:
Design a blue print of how to 'efficiently' persist the state of the system.
Consider what kind of queries will be made (read vs write), are there any joins required
consequently figure out the columns for indexing
Use Normalization, ACID properties.
PS: notice the both the diagram tries to efficiently do thing in their on respect.

which should be drawn first , class or sequence diagram?

I've had this discussion with my professor at college about UML diagrams .
He believes that sequence diagrams should be drawn before getting to class diagrams, but I think the opposite . I think after finishing the usecase diagram , the next diagram should be class diagram and after that we should get to sequence diagram.
Rational rose requires us to use the classes in sequence diagram, which are already in class diagram.
Can anyone help me with this?
I think you're both wrong. They should be drawn at the same time. As you're drawing your sequence diagram, you will undoubtedly come up with properties that you will need to keep track of the state, or that you hadn't thought of if you do the class diagram in a vacuum.
Of course, this is highly subjective and personal, but years of real-world experience (as opposed to academic theory) have taught me to work on both at the same time. MAYBE starting with the class diagram, but the class diagram invariably changes when you start going through process flows.
Well it depends a lot on how you plan to do things. I think it's a subjective matter. If you rather explain the actions performed for your usecases and after this has been done write the classes based on what you need to perform the sequences your professor is right.
But if you prefer to determine what the structure of your classes are and then adapt the action sequence to this then you would do the class diagram first and later the sequence.
In my experience I do them concurrently. I put the fundamental attributes to the class diagram but not the actions, and while I do the sequence diagram I add the methods and attributes that I need to the class diagram.
There is no one standard answer. There are several opinions, approaches and methods. In Unified Process I believe you first identify use case and then make realizations for them, e.g. sequence diagrams. As in use cases, there are actors and the systems and/or its parts interacting ina sequence. Actually this interactions should help you decompose your design and get to classes. Once you have classes on the analysis level, you can go further to design classess and design interactions. However these are quite a lot to draw in a diagram, most of the times code is the best documentation on this level, even generated diagrams are too large and more difficult to understand then code itself.
To prepare sequence diagram you need classes not the class diagram
You can prepare empty classes on the fly while in process of preparing sequence diagram....
Identification class objects in be part of preparing sequence or you can try to identify your objects before hand....
sequence is logical process while class diagram is end output
I don't think there is an order for creating diagrams since both are two different views of a system: class diagram structural (static) and sequence is behavioral (dynamic). I would start with sequence diagrams since you will discover more classes to create as you go through sequences. Do whatever makes sense for you at the time. If your doing more object oriented programming, I would consider doing classes before sequences.
Structural and behavioural models for all but the very simplest systems are naturally created simultaneously and iteratively, refining both over time.
You may have some method of "object discovery" such as CRC cards, which will yield a set of initial classes, with collaborations (the classes they interact with) and responsibilities, which informs both the methods they will need, and internal behaviour/state/activity.
You may then want to explore the use cases and scenarios using sequence or communication diagrams, this will expose the details of the required object communication and therefore inform the generation of public methods and relationships to refine the class diagram while at the same exploring the system behaviour which may yield further objects and classes to be created.
You may also want to explore the internal behaviour of classes, especially if they have stateful and/or active behaviour; activity ans state-machine diagrams are useful for this.
Either way I doubt that the use of Rational Rose is really the determinant of diagram creation order. Rational may require the classes on a sequence diagram to exist, but I imagine that they need not actually appear on a class diagram; they can probably equally be created on the sequence diagram and then later placed on a class diagram, or even created in the project explorer or whatever the equivalent is in that tool. Even if the only method of creating a class is to place it on a class diagram, that does not require you to refine and complete the class or its relationships before exploring interactions on a sequence diagram.
You need to buy some clothes, how you will proceed. You start choosing clothes first or you will decide first where to go? At the same time, will you go to shoe store if you want to buy shirt.
So both are iterative, but definitely first step is sequence on very high (component) level then drill down to class level sequence
You should first decide your application flow,means you should first draw a sequence diagram. It will show the flow of your application after this you should go for class diagram.

Resources