Class and Sequence Modeling
Aim:- To create a class and activity diagram for a software project.
Background:-
Class Diagram
Classes are the structural units in object oriented system design approach, so it is essential to know all
the relationships that exist between the classes, in a system. All objects in a system are also interacting
to each other by means of passing messages from one object to another. Sequence diagram shows
these interactions with time ordering of the messages.
In this Experiment, we will learn about the representation of class diagram and sequence diagram. We
also learn about different relationships that exist among the classes, in a system.
From the experiment of sequence diagram, we will learn about different types of messages passing in
between the objects and time ordering of those messages, in a system.
Structural and Behavioral aspects
Developing a software system in object oriented approach is very much dependent on understanding
the problem. Some aspects and the respective models are used to describe problems and in context of
those aspects the respective models give a clear idea regarding the problem to a designer. For
developer, structural and behavioral aspects are two key aspects to see through a problem to design a
solution for the same.
Class diagram
It is a graphical representation for describing a system in context of its static construction.
Elements in class diagram
Class diagram contains the system classes with its data members, operations and relationships
between classes.
Class
A set of objects containing similar data members and member functions is described by a class. In
UML syntax, class is identified by solid outline rectangle with three compartments which contain
Class name: A class is uniquely identified in a system by its name. A textual string is taken as
class name. It lies in the first compartment in class rectangle.
Attributes: Properties shared by all instances of a class. It lies in the second compartment in class
rectangle.
Operations: An execution of an action can be performed for any object of a class. It lies in the last
compartment in class rectangle.
Generalization/Specialization: It describes how one class is derived from another class.
Derived class inherits the properties of its parent class.
Relationships
Existing relationships in a system describe legitimate connections between the classes in that system.
Association: It is an instance level relationship that allows exchanging messages among the
objects of both ends of association. A simple straight line connecting two class boxes
represent an association. We can give a name to association and also at the both end we may
indicate role names and multiplicity of the adjacent classes. Association may be uni-
directional.
Aggregation: It is a special form of association which describes a part-whole relationship
between a pair of classes. It means, in a relationship, when a class holds some instances of
related class, then that relationship can be designed as an aggregation.
Composition: It is a strong from of aggregation which describes that whole is completely
owns its part. Life cycle of the part depends on the whole.
Multiplicity: It describes how many numbers of instances of one class is related to the number
of instances of another class in an association.
Sequence diagram
It represents the behavioral aspects of a system. Sequence diagram shows the interactions between the
objects by means of passing messages from one object to another with respect to time in a system.
Elements in sequence diagram
Sequence diagram contains the objects of a system and their life-line bar and the messages passing
between them.
Object: Objects appear at the top portion of sequence diagram. Object is shown in a rectangle
box. Name of object precedes a colon ‘:’ and the class name, from which the object is
instantiated. The whole string is underlined and appears in a rectangle box. Also, we may use
only class name or only instance name. Objects which are created at the time of execution of
use case and are involved in message passing , are appear in diagram, at the point of their
creation.
Life-line bar: A down-ward vertical line from object-box is shown as the life-line of the
object. A rectangle bar on life-line indicates that it is active at that point of time.
Messages
Messages are shown as an arrow from the life-line of sender object to the life-line of receiver
object and labeled with the message name. Chronological order of the messages passing
throughout the objects’ life-line show the sequence in which they occur. There may exist
some different types of messages:
o Synchronous messages:Receiver start processing the message after receiving it and
sender needs to wait until it is made. A straight arrow with close and fill arrow-head
from sender life-line bar to receiver end, represent a synchronous message.
o Asynchronous messages: For asynchronous message sender needs not to wait for the
receiver to process the message. A function call that creates thread can be represented
as an asynchronous message in sequence diagram. A straight arrow with open arrow-
head from sender life-line bar to receiver end, represent an asynchronous message.
o Return message: For a function call when we need to return a value to the object,
from which it was called, then we use return message. But, it is optional, and we are
using it when we are going to model our system in much detail. A dashed arrow with
open arrow-head from sender life-line bar to receiver end, represent that message.
o Response message: One object can send a message to self. We use this message when
we need to show the interaction between the same object.
Tasks: Draw a class diagram and a sequence diagram