Sequence Diagram - Lifeline modelled as Class or System - uml

is it allowed to draw a sequence diagram with classes and systems as lifelines.
For example:
I want to model a part of the domain logic with a sequence diagram. Can I model a the lifeline once as a class and once as a whole system (remote system or a whole layer/jar file)?
Example-1:
There is the Class Scheduler which invokes the FileDownloader class which calls a FileServer? So I have the "Scheduler" (Class) the "FileDownloader" (Class) and the "FileServer"(remote System) as a lifeline.
Example-2:
Or I have a Class called Scheduler which invokes the "AccountingService" which calls the "Persistence Layer" which calls the "Database"
So I have the "Scheduler" (Class) the "AccountingService"(Class) the "PersistenceyLayer" (Whole Layer or .jar File) and the "Database" (System).
Is it allowed to mix these up in a sequence diagram. In some descriptions about sequence diagrams there would only modelled classes that call classes or systems that call systems.
Thanks.

What do you mean by "System" ? In UML there is not definition of system. You probably mean System as a name of Class or Component, or is it a stereotype? If yes, you can mix it.
Jar file is artifact. Artifact is Classifier as well. If artifact plays role in internal or communication structure, it can be represented by lifeline as well.
Lifeline represents instance of specific type which participate in interaction. Referenced type could be any connectable element from classifier owning interaction (sequence diagram, for example Class, Component or other types of classifiers).
To learn more about UML, I recommend you to read UML superstructure specification document.
Dowload it for free from omg.. UML Superstructure

Lifeline usually represents a role (it can be what you call system or even a human being), or an object. Notice, not class but its instance! Lifeline represents any thing with some behaviour. Classes mostly describe not their own behaviour, but behaviour of their instances. You'll have a class as a timeline only when you are modelling its static fields and functions. Or when you are in JS or similar language and your class is really a prototype
So, mixing of large and small objects, components or roles is absolutely OK. It is a part of standard UML usage. But do not mix instances and classes if you are modelling for "traditional" languages! Are you sure that it is the class "Sheduler" that invokes something, and not an instance myBestSheduler of this class?

In sequence diagrams, displaying a class means "when I make an instance / object of this class, this activities occur".
And, other external stuff, that interact with your program, like the users ("actors"), Shared Libraries /DLLs, Web Services, Operating System, Network, whatever ...
... are considered objects ("instance of a class").
A Sequence Diagram, is composed by several objects, each one, with its own "Lifeline" or "TimeLine", that interact among them, (several "Lifeline (s)").

Related

Representing the lifeline objects in the UML Sequence Diagram

I am building a system with no classes and objects, only a database. And I was wondering if it is correct to implement the sequence diagram with System and Database as the only objects in the diagram as shown in the picture.
Extract of My Sequence Diagram
You can use a sequence diagram to model exchanges not only between instances of classes, but also between instances of components or subsystems. This can be extended to systems if you’re modelling a system of systems. So your approach is perfectly acceptable (and it can really help).
By the way, the fact that a DBMS is not an object in the sense of OOP, does not prevent you from modeling it as an object, since it is encapsulated, has an internal state, and offers behavior via a well-defined interface.
The only ambiguous thing in your diagram is the actor, since lifelines should be internal to the system whereas actors are external. But it’s a common practice, even if messages exchanged are not as formally defined as one would expect in a traditional sequence diagram.

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.

Class diagram drawn from Use case description

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.

Class diagram vs State diagram (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.

What kind of diagram can I use to show method execution within a class?

Is there a type of UML diagram that can be used to map out method execution within a class? The class in question has two public methods and the rest are private. I have already constructed a sequence diagram to show how interaction with the class in the context of other objects but would something like a flow diagram be appropriate to display the order of method execution within a class?
No matter your methods involved in the execution sequence belong to the same class or not you may use the sequence diagram.
If the intend is to describe the class internal heuristic than an activity diagram is more appropriate.
If methods invocations in your class are ordered or restricted by specific rules, you should use Protocol StateMachine. Protocol StateMachine is used, when communication protocol should be defined for interaction with owning class.
You can find detailed information in UML Superstructure document, part ProtocolStateMachine.
UML Website

Resources