Class diagram vs State diagram (UML) - uml

Can someone give me an example of when is better to use State Diagram and when Class Diagram. Tnx in advance!
For what type of software system would you use state machine diagrams to model functional requirements?
For what type of software system is data modeling via UML class diagrams suitable?

A class diagram shows classes in their relation and their properties and methods.
A state diagram visualizes a class's states and how they can change over time.
In both cases you are talking about diagrams which are only a window into the model. The class relations define how the single classes relate to each other. A state machine can be defined for each class to show its states. In embedded systems you use state machines almost all the time but there are also state machines for business applications (you can do this if that).

This question reveals a very common misunderstanding. There are only thirteen types of diagram in UML. They're not used to describe different types of system, but to describe different aspects of the system you are documenting. Which you pick in any given situation is more a question of style, what you want to emphasize.
It is better to use state diagrams if you want to focus on how the system can go into different states in response to various events. Activity diagrams are better if you want to focus on activities being carried out in some order, sequence diagrams are better if you want to show messages being sent between entities.
The above are all types of diagram which show behaviour. Class diagrams are a different type of beast altogether, and show how structures of things fit together (as do package diagrams and component diagrams).
It might be worth pointing out that while UML does not include a "requirement" element type, the related modelling language SysML does. If you want to express a number of functional requirements on the form "the system shall" in a model, SysML is a better fit.

A state diagram shows the behavior of the class. A class model shows the relationship between two or more classes. It includes its properties/attributes...
A state is an allowable sequence of changes of objects of a class model.

Related

Interface depictions in communication diagram or System sequence diagram?

I was searching around for a simple example depiction on how it would look if class Professor and Class Student would both implement and interface from Class Person in a communication diagram or System sequence diagram.
I think its depicted as this a class diagram:
But i am curious if it can be depicted in a communication diagram or System sequence diagram ?
You can show anything in any diagram type. Citing p. 683 of UML 2.5:
NOTE. This taxonomy provides a logical organization for the various major kinds of diagrams. However, it does not preclude mixing different kinds of diagram types, as one might do when one combines structural and behavioral elements (e.g., showing a state machine nested inside an internal structure). Consequently, the boundaries between the various kinds of diagram types are not strictly enforced.
I think, that's more than clear.

UML Metamodel for associations between diagrams

up until now, I always ignored the UML Metamodel, but now that I've taken a closer look at it, I have a question which isn't answered by the standard books which I have at hand.
The Metamodel describes elements and their associations per diagram. So, it defines for instance what kind of relationship an actor can have with a use case in a use case diagram.
But does it also describe the relationships / associations between diagrams? Or maybe better expressed between elements of different diagrams?
Example:
In a class diagram, I define how I structure my code. This is defined by the metamodel
In a deployment diagram, I specify how I deploy artifacts to execution nodes. Also defined by the metamodel
But does the metamodel also define relationships with which I can specify how I derive the artifact (which I deploy, maybe a .jar file) from my code?
Diagrams are only a view onto the model. So you can show any arbitrary part of your model. Preferably you create a number of different structural diagrams to explain your model structure. Those are later augmented with behavioral diagrams which show how certain elements collaborate.
tl;dr UML is not about diagramming.
Yes, metamodel explains how various elements of a model can be connected. Diagrams itself represent poets puff the model and it is also described in a metamodel. While it's not always clearly shown how to actually represent that, for example each behavioral model represent behavior of something. What can have this type of behaviour is part of metamodel.
Let's look at specific example.
Consider State Machine. Metamodel defines which elements can have State Machines (e.g. A class). So if you have a certain class you can draw a diagram of State Machine owned by this class. How to show that this SM is owned by that class is a different story but that is also possible with UML.
Then on a state machine you can have activities which according to metamodel have to be owned by the same class etc.
One remark - it's spread over the whole specification. But look at definitions of elements like classifier, behaviour, state machine etc. That's where your answer is.

Are all objects on sequence diagram should be designed in class diagram?

I'm working on sequence & class diagram for education website, should all objects in sequence diagram be a class in Class diagram?
For example in sequence diagram for registration process I need an object called "Data Base" which needed for saving information of user, should "Date base" be a class in class diagram? and what can be its functions? Is it just load & save?
I think it depends on the level of formality, abstraction, and the purpose of your UML model.
Martin Fowler talks about UML as Sketch, UML as Blueprint, and UML as Programming Language.
The terminology has gotten some good usage; and I think 'UML as Sketch' in particular has emerged as a popular mode, with the goal of human-to-human communication about the design of a system; not necessarily a formal engineering specification (i.e. a blueprint), nor suitable as an input to a code generator (i.e. a programming language).
If you want to use UML in Sketch mode, which is perfectly valid, then it's not a requirement for your sequence diagrams to use only the classes defined in your class diagram. In fact, some of the objects/lifelines in a sequence diagram aren't class instances at all:
They may be "actors" defined in a use case diagram (or not). Actors are often people, and as such are represented as stick figures. "End user" is a common actor to include in a sequence diagram. Plenty of examples here.
They may be external systems, like a database, that are not defined in your class model. Your system might have a class, or set of classes, to abstract the database, i.e. a "data access layer" or DAL. But then again, your system might not have a DAL; and even if it does, you might still want your sequence diagram to show the interactions across the boundary, between the DAL and the actual database.
Using UML as a sketch, the methods implemented by external actors or system components are really up to you. You could show a database query as execute query, or something more specific, like an actual SQL statement. The "correctness" of your diagram is in its ability to communicate effectively with your audience, at the right level of detail and formality.
Yes, the Database would be a class in Class Diagram and its functions can be validation() , generatingErrorMessage() etc.

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