FIRST OF ALL WHAT IS UML?
UML IS a unified modeling language is the general purpose , modeling language in software engineering field that is intended to provide a standard way of visualizing a design of the system!
Interaction diagrams means the interaction of the different part with in the system
INTERACTION DIAGRAM are used in UML to establish communication between objects. It does not manipulate the data associated with the particular communication path. Interaction diagrams mostly focus on message passing and how these messages make up one functionality of a system. Interaction diagrams are designed to display how the objects will realize the particular requirements of a system. The critical component in an interaction diagram is lifeline and messages.
Various UML elements typically own interaction diagrams. The details of interaction can be shown using several notations such as sequence diagram, timing diagram, communication/collaboration diagram. Interaction diagrams capture the dynamic behavior of any system.
Following are the different types of interaction diagrams defined in UML:
The purpose of a sequence diagram in UML is to visualize the sequence of a message flow in the system. The sequence diagram shows the interaction between two lifelines as a time-ordered sequence of events.
The collaboration diagram is also called as a communication diagram. The purpose of a collaboration diagram is to emphasize structural aspects of a system, i.e., how various lifelines in the system connects.
Timing diagrams focus on the instance at which a message is sent from one object to another object.
What You Will Learn: [show]
Interaction diagrams help you to visualize the interactive behavior of a system. Interaction diagrams are used to represent how one or more objects in the system connect and communicate with each other.
Interaction diagrams focus on the dynamic behavior of a system. An interaction diagram provides us the context of an interaction between one or more lifelines in the system.
In UML, the interaction diagrams are used for the following purposes:
An interaction diagram contains lifelines, messages, operators, state invariants and constraints.
A lifeline represents a single participant in an interaction. It describes how an instance of a specific classifier participates in the interaction.
A lifeline represents a role that an instance of the classifier may play in the interaction. Following are various attributes of a lifeline,
The notation of lifeline is explained in the notation section.
A message is a specific type of communication between two lifelines in an interaction. A message involves following activities,
When a lifeline receives a call message, it acts as a request to invoke an operation that has a similar signature as specified in the message. When a lifeline is executing a message, it has a focus of control. As the interaction progresses over time, the focus of control moves between various lifelines. This movement is called a flow of control.
Following are the messages used in an interaction diagram:
Message Name | Meaning |
Synchronous message | The sender of a message keeps waiting for the receiver to return control from the message execution. |
Asynchronous message | The sender does not wait for a return from the receiver; instead, it continues the execution of a next message. |
Return message | The receiver of an earlier message returns the focus of control to the sender. |
Object creation | The sender creates an instance of a classifier. |
Object destruction | The sender destroys the created instance. |
Found message | The sender of the message is outside the scope of interaction. |
Lost message | The message never reaches the destination, and it is lost in the interaction. |
When an instance or a lifeline receives a message, it can cause it to change the state. A state is a condition or a situation during a lifetime of an object at which it satisfies some constraint, performs some operations, and waits for some event.
In interaction diagram, not all messages cause to change the state of an instance. Some messages do not the values of some attribute. It has no side effects on the state of an object.
An operator specifies an operation on how the operands are going to be executed. The operators in UML supports operations on data in the form of branching as well as an iteration. Various operators can be used to ensure the use of iteration and branching in the UML model. The opt and alt operators are used for branching operations. The loop operator is used to ensure the iteration operations in which a condition is executed repeatedly until the satisfying result is produced. Break operator is used inside the loop or iteration operations. It ensures that the loop is terminated whenever a break operator is encountered. If a break condition is not specified, then the loop executes the infinite number of times, which results in crashing the program.
Following are the operators used in an interaction diagram:
Operator | Name | Meaning |
Opt | Option | An operand is executed if the condition is true. e.g., If else |
Alt | Alternative | The operand, whose condition is true, is executed. e.g., switch |
Loop | Loop | It is used to loop an instruction for a specified period. |
Break | Break | It breaks the loop if a condition is true or false, and the next instruction is executed. |
Ref | Reference | It is used to refer to another interaction. |
Par | Parallel | All operands are executed in parallel. |
In an interaction diagram, we can also show iteration using an iteration expression. An iteration expression consists of an iteration specifier and an optional iteration clause. There is no pre-specified syntax for UML iteration.
In iteration to show that messages are being sent in parallel, parallel iteration specifier is used. A parallel iteration specifier is denoted by *//. Iteration in UML is achieved by using the loop operator.
In an interaction diagram, we can represent branching by adding guard conditions to the messages. Guard conditions are used to check if a message can be sent forward or not. A message is sent forward only when its guard condition is true. A message can have multiple guard conditions, or multiple messages can have the same guard condition. Branching in UML is achieved with the help of alt and opt, operators.
These are some of the most important terminologies used in UML interaction diagram.
Following are the different types of interaction diagrams defined in UML:
The basic notation of interaction is a rectangle with a pentagon in the upper left corner of a rectangular box.
A SEQUENCE DIAGRAM simply depicts interaction between objects in a sequential order. The purpose of a sequence diagram in UML is to visualize the sequence of a message flow in the system. The sequence diagram shows the interaction between two lifelines as a time-ordered sequence of events.
The above sequence diagram contains lifeline notations and notation of various messages used in a sequence diagram such as a create, reply, asynchronous message, etc.
The following sequence diagram example represents McDonald's ordering system:
The ordered sequence of events in a given sequence diagram is as follows:
If one changes the order of the operations, then it may result in crashing the program. It can also lead to generating incorrect or buggy results. Each sequence in the above-given sequence diagram is denoted using a different type of message. One cannot use the same type of message to denote all the interactions in the diagram because it creates complications in the system.
You must be careful while selecting the notation of a message for any particular interaction. The notation must match with the particular sequence inside the diagram.
COLLABORATION DIAGRAM depicts the relationships and interactions among software objects. They are used to understand the object architecture within a system rather than the flow of a message as in a sequence diagram. They are also known as “Communication Diagrams.”
As per Object-Oriented Programming (OOPs), an object entity has various attributes associated with it. Usually, there are multiple objects present inside an object-oriented system where each object can be associated with any other object inside the system. Collaboration Diagrams are used to explore the architecture of objects inside the system. The message flow between the objects can be represented using a collaboration diagram.
The above collaboration diagram notation contains lifelines along with connectors, self-loops, forward, and reverse messages used in a collaboration diagram.
Following diagram represents the sequencing over student management system:
The above collaboration diagram represents a student information management system. The flow of communication in the above diagram is given by,
TIMING DIAGRAM is a waveform or a graph that is used to describe the state of a lifeline at any instance of time. It is used to denote the transformation of an object from one form into another form. Timing diagram does not contain notations as required in the sequence and collaboration diagram. The flow between the software program at various instances of time is represented using a waveform.
The timing diagram given below represents a few phases of a software development life cycle.
In the above diagram, first, the software passes through the requirements phase then the design and later the development phase. The output of the previous phase at that given instance of time is given to the second phase as an input. Thus, the timing diagram can be used to describe SDLC (Software Development Life Cycle) in UML.
Interaction diagrams are used to represent the interactive behavior of a system. Interaction diagrams focus on the dynamic behavior of a system. An interaction diagram provides us the context of an interaction between one or more lifelines in the system.
To draw an interaction diagram, you have first to determine the scenario for which you have to draw an interaction diagram. After deciding the situation, identify various lifelines that are going to be involved in the interaction. Categorize all the lifeline elements and explore them to identify possible connections and how the lifelines are related to one another. To draw an interaction diagram, the following things are required:
Interaction diagrams consist of a sequence diagram, collaboration diagram, and timing diagrams. Following is the specific purpose of an interaction diagram: