Chapter 2 System Analusis and Modelling
Chapter 2 System Analusis and Modelling
Identifying objects
Organizing the objects by creating object model diagram
Defining the internals of the objects, or object attributes
Defining the behavior of the objects, i.e., object actions
Describing how the objects interact
The common models used in OOA are use cases and object models.
Object-Oriented Design:-
Page 1
solution domain, i.e., a detailed description of how the system is to be built on
concrete technologies.
The implementation details generally include −
Object-Oriented Programming:-
Page 2
Class
A class represents a collection of objects having same characteristic
properties that exhibit common behavior. It gives the blueprint or description
of the objects that can be created from it. Creation of an object as a member
of a class is called instantiation. Thus, object is an instance of a class.
Example
Let us consider a simple class, Circle, that represents the geometrical figure
circle in a two–dimensional space. The attributes of this class can be
identified as follows −
x–coord, to denote x–coordinate of the center
y–coord, to denote y–coordinate of the center
a, to denote the radius of the circle
Some of its operations can be defined as follows −
findArea(), method to calculate area
findCircumference(), method to calculate circumference
scale(), method to increase or decrease the radius
During instantiation, values are assigned for at least some of the attributes. If
we create an object my_circle, we can assign values like x-coord : 2, y-coord
: 3, and a : 4 to depict its state. Now, if the operation scale() is performed on
my_circle with a scaling factor of 2, the value of the variable a will become
8. This operation brings a change in the state of my_circle, i.e., the object
has exhibited certain behavior
Page 3
A class is an entity that determines how an object will behave and what the object
will contain. In other words, it is a blueprint or a set of instruction to build a
specific type of object. It provides initial values for member variables and member
functions or methods.
Object
An object is a real-world element in an object–oriented environment that may have
a physical or a conceptual existence. Each object has −
Objects can be modelled according to the needs of the application. An object may
have a physical existence, like a customer, a car, etc.; or an intangible conceptual
existence, like a project, a process, etc.
For example, when you send a message to an object, you are asking the object to
invoke or execute one of its methods.
Let's take an example of developing a pet management system, specially meant for
dogs. You will need various information about the dogs like different breeds of the
dogs, the age, size, etc.
Page 4
You need to model real-life beings, i.e., dogs into software entities.
Moreover, the million dollar question is, how you design such software? Here is
the solution-
You can see the picture of three different breeds of dogs below.
Stop here right now! List down the differences between them.
Some of the differences you might have listed out maybe breed, age, size, color,
etc. If you think for a minute, these differences are also some common
characteristics shared by these dogs. These characteristics (breed, age, size, color)
can form a data members for your object.
Page 5
Next, list out the common behaviors of these dogs like sleep, sit, eat, etc. So these
will be the actions of our software objects.
Page 6
Class: Dogs
Now, for different values of data members (breed size, age, and color) in C++ or
Java class, you will get different dog objects.
Page 7
You can design any program using this OOPs approach.
Page 8
Class Object
A class does not allocate memory space Object allocates memory space whenever
when it is created. they are created.
You can declare class only once. You can create more than one object using a
class.
It doesn't have any values which are Each and every object has its own values,
associated with the fields. which are associated with the fields.
Page 9
Class Object
Class is a blueprint or template from Object is an instance of a class.
which objects are created.
Class is a group of similar objects. Object is a real world entity such as pen,
laptop, mobile, bed, keyboard, mouse,
chair etc.
Class is a logical entity. Object is a physical entity.
Class is declared once. Object is created many times as per
requirement.
Class doesn't allocated memory when Object allocates memory when it is
it is created. created.
Let's see some real life example of class and object in OOPS to understand the
difference well:
Abstraction
Abstraction is the concept of object-oriented programming that "shows" only
essential attributes and "hides" unnecessary information. The main purpose of
abstraction is hiding the unnecessary details from the users. Abstraction is
selecting data from a larger pool to show only relevant details of the object to the
user. It helps in reducing programming complexity and efforts. It is one of the most
important concepts of OOPs.
Data Abstraction is the property by virtue of which only the essential details are
displayed to the user. The trivial or the non-essentials units are not displayed to the
user. Ex: A car is viewed as a car rather than its individual components.
Data Abstraction may also be defined as the process of identifying only the
required characteristics of an object ignoring the irrelevant details. The properties
Page 10
and behaviors of an object differentiate it from other objects of similar type and
also help in classifying/grouping the objects.
a class is designed such that its data (attributes) can be accessed only by its class
methods and insulated from direct outside access. This process of insulating an
object’s data is called data hiding or information hiding.
In the class Circle, data hiding can be incorporated by making attributes invisible
from outside the class and adding two more methods to the class for accessing
class data, namely −
Here the private data of the object my_circle cannot be accessed directly by any
method that is not encapsulated within the class Circle. It should instead be
accessed through the methods setValues() and getValues().
Example of Abstraction:
#include <iostream>
class Summation {
private:
// private variables
public:
myNum1 = inNum1;
myNum2 = inNum2;
Page 11
cout << "Sum of the two number is : " << myNum3< <endl;
};
int main()
Summation mySum;
mySum.sum(5, 4);
return 0;
In this case the variables myNum1, myNum2 and myNum3 are private, thereby in
accessible to any code other than the class Summation. In this example
the variables are set to values passed in as arguments to the sum method. This is
not a very true example - often the values would NOT be set just before being used
like this, but it shows the reality of the implementation.
Output:
Encapsulation
Encapsulation is a method of making a complex system easier to handle for end
users. The user need not worry about internal details and complexities of the
system. Encapsulation is a process of wrapping the data and the code, that operate
on the data into a single entity. You can assume it as a protective wrapper that
stops random access of code defined outside that wrapper.
Page 12
think about encapsulation is, it is a protective shield that prevents the data from
being accessed by the code outside this shield.
Encapsulation can be achieved by Declaring all the variables in the class as private
and writing public methods in the class to set and get the values of variables.
Encapsulation is the process of binding both attributes and methods together within
a class. Through encapsulation, the internal details of a class can be hidden from
outside. It permits the elements of the class to be accessed from outside only
through the interface provided by the class.
For Example
#include <iostream>
using namespace std;
class Adder {
public:
// constructor
Adder(int i = 0) {
total = i;
}
// interface to outside world
void addNum(int number) {
total += number;
}
// interface to outside world
int getTotal() {
return total;
};
Page 13
private:
// hidden data from outside world
int total;
};
int main() {
Adder a;
a.addNum(10);
a.addNum(20);
a.addNum(30);
Above class adds numbers together, and returns the sum. The public
members addNum and getTotal are the interfaces to the outside world and a user
needs to know them to use the class. The private member total is something that is
hidden from the outside world, but is needed for the class to operate properly.
#include<iostream>
class Encapsulation
Page 14
private:
int x;
public:
// variable x
void set(int a)
x =a;
// variable x
int get()
return x;
Page 15
}
};
// main function
int main()
Encapsulation obj;
obj.set(5);
cout<<obj.get();
return 0;
output:
5
In the above program the variable x is made private. This variable can be accessed
and manipulated only using the functions get() and set() which are present inside
the class. Thus we can say that here, the variable x and the functions get() and set()
are binded together which is nothing but encapsulation.
Page 16
Another Example :-
#include <iostream>
class EncapsulationExample {
private:
int number1;
public:
number1 = input1;
int get()
return number1;
Page 17
};
// main function
int main()
EncapsulationExample myInstance;
myInstance.set(10);
return 0;
In the this program, the variable number1 is made private so that this variable can
be accessed and manipulated only by using the methods get() and set() that are
present within the class. Therefore we can say that, the variable a and the methods
set() as well as get() have bound together that is encapsulation. There is nothing
special about the method names "get()" or "set()" - there may be other methods that
manipulate the variable number1...all together this is called encapsulation.
Output:
10
ABSTRACTION ENCAPSULATION
Abstraction is the process or method of encapsulation is the process or method
gaining the information. to contain the information.
In abstraction, problems are solved at While in encapsulation, problems are
the design or interface level. solved at the implementation level.
Abstraction is the method of hiding the Whereas encapsulation is a method to
unwanted information. hide the data in a single entity or unit
along with a method to protect
information from outside.
Page 18
In abstraction, implementation While in encapsulation, the data is
complexities are hidden using abstract hidden using methods of getters and
classes and interfaces setters
The objects that help to perform Whereas the objects that result in
abstraction are encapsulated. encapsulation need not be abstracted.
Method :-
Methods are functions that belongs to the class.
Page 19
In the following example, we define a function inside the class, and we name it
"myMethod".
Note: You access methods just like you access attributes; by creating an object of
the class and using the dot syntax (.):
};
int main() {
return 0;
To define a function outside the class definition, you have to declare it inside the
class and then define it outside of the class. This is done by specifiying the name of
Page 20
the class, followed the scope resolution :: operator, followed by the name of the
function:
};
void MyClass::myMethod() {
int main() {
return 0;
Page 21
#include <iostream>
class Car {
public:
};
return maxSpeed;
int main() {
return 0;
Output :- 200
Message Passing
Any application requires a number of objects interacting in a harmonious manner.
Objects in a system may communicate with each other using message passing.
Suppose a system has two objects: obj1 and obj2. The object obj1 sends a message
to object obj2, if obj1 wants obj2 to execute one of its methods.
Page 22
Message passing enables all interactions between objects.
A message is what you send, asking for something to be done by the object you’ve
sent the message to. A method is the code that actually gets run by that receiving
object, after the system has looked up the match between the receiver and the
message.
1. This model is much easier to implement than the shared memory model.
In OOPs, there are many ways to implement the message passing technique like
message passing through constructors, message passing through methods or by
passing different values. The following is a simple implementation of the message
passing technique by the values:
import java.io.*;
Page 23
// class
// Implementing a method to
int z = x + y;
System.out.println(
float z = x * y;
System.out.println(
class GFG {
// Driver code
Page 24
public static void main(String[] args)
MessagePassing mp
= new MessagePassing();
// the answer
mp.displayInt(1, 100);
mp.displayFloat((float)3, (float)6.9);
Output:
Interface: -
Like a class, an interface can have methods and variables, but the methods declared
in an interface are by default abstract (only method signature, no body).
Interfaces specify what a class must do and not how. It is the blueprint of the
class.
Page 25
An Interface is about capabilities like a Player may be an interface and any
class implementing Player must be able to (or must implement) move(). So
it specifies a set of methods that the class has to implement.
If a class implements an interface and does not provide method bodies for all
functions specified in the interface, then the class must be declared abstract.
Since java does not support multiple inheritance in case of class, but by
using interface it can achieve multiple inheritance .
Interfaces are used to implement abstraction. So the question arises why use
interfaces when we have abstract classes?
Interfaces make it easy to use a variety of different classes in the same way.
When one or more classes use the same interface, it is referred to as
"polymorphism".
An interface can define method names and arguments, but not the contents
of the methods.
Page 26
A class can implement multiple interfaces.
Class Interface
Page 27
Use an abstract class when a template needs to be defined for a group of
subclasses
Use an interface when a role needs to be defined for other classes, regardless
of the inheritance tree of these classes
A Java class can implement multiple Java Interfaces. It is necessary that the
class must implement all the methods declared in the interfaces.
Class should override all the abstract methods declared in the interface
An interface can extend from one or many interfaces. Class can extend only
one class but implement any number of interfaces
The class cannot implement two interfaces in java that have methods with
same name but different return type.
Inheritance
Page 28
Inheritance is the mechanism that permits new classes to be created out of
existing classes by extending and refining its capabilities. The existing
classes are called the base classes/parent classes/super-classes, and the new
classes are called the derived classes/child classes/subclasses. The subclass
can inherit or derive the attributes and methods of the super-class(es)
provided that the super-class allows so. Besides, the subclass may add its
own attributes and methods and may modify any of the super-class methods.
Inheritance defines an “is – a” relationship.
Example
Types of Inheritance
Page 29
Polymorphism
Page 30
Polymorphism as the ability of a message to be displayed in more than one form
The word polymorphism means having many forms. In simple words, we can
define.
Real life example of polymorphism: A person at the same time can have different
characteristic. Like a man at the same time is a father, a husband, an employee. So
the same person posses different behavior in different situations. This is called
polymorphism.
Example
Let us consider two classes, Circle and Square, each with a method findArea().
Though the name and purpose of the methods in the classes are same, the internal
implementation, i.e., the procedure of calculating area is different for each class.
When an object of class Circle invokes its findArea() method, the operation finds
the area of the circle without any conflict with the findArea() method of the Square
class.
Polymorphism in Java occurs when there are one or more classes or objects
related to each other by inheritance. It is the ability of an object to take many
forms. Inheritance lets users inherit attributes and methods, and polymorphism
uses these methods to perform different tasks. So, the goal is communication, but
the approach is different.
Page 31
message, mail, etc. So, the goal is common that is communication, but their
approach is different. This is called Polymorphism.
We have one parent class, ‘Account’ with function of deposit and withdraw.
Account has 2 child classes
The operation of deposit and withdraw is same for Saving and Checking accounts.
So the inherited methods from Account class will work.
For a background, overdraft is a facility where you can withdraw an amount more
than available the balance in your account.
So, withdraw method for privileged needs to implemented afresh. But you do not
change the tested piece of code in Savings and Checking account. This is
advantage of OOPS
Page 32
Step 1) Such that when the "withdrawn" method for saving account is called
a method from parent account class is executed.
Page 33
Step 2) But when the "Withdraw" method for the privileged account
(overdraft facility) is called withdraw method defined in the privileged class
is executed. This is Polymorphism in OOPs.
UML :-
Page 34
Although UML is generally used to model software systems, it is not limited
within this boundary. It is also used to model non-software systems as well.
For example, the process flow in a manufacturing unit, etc.
UML is not a programming language but tools can be used to generate code
in various languages using UML diagrams
Page 35
As UML describes the real-time systems, it is very important to make a conceptual
model and then proceed gradually. The conceptual model of UML can be mastered
by learning the following three major elements −
Things
Relationships
Diagrams
Things
Things are the most important building blocks of UML. Things can be −
Structural
Behavioral
Grouping
Annotational
Structural Things
Structural things define the static part of the model. They represent the physical
and conceptual elements. Following are the brief descriptions of the structural
things.
Page 36
Interface − Interface defines a set of operations, which specify the responsibility
of a class.
Use case −Use case represents a set of actions performed by a system for a specific
goal.
Node − A node can be defined as a physical element that exists at run time.
Behavioral Things
A behavioral thing consists of the dynamic parts of UML models. Following are
the behavioral things −
Page 37
State machine − State machine is useful when the state of an object in its life
cycle is important. It defines the sequence of states an object goes through in
response to events. Events are external factors responsible for state change
Grouping Things-
Package − Package is the only one grouping thing available for gathering
structural and behavioral things.
Annotational Things-
Relationship-
Relationship is another most important building block of UML. It shows how the
elements are associated with each other and this association describes the
functionality of an application.
Page 38
Dependency-
Association-
Association is basically a set of links that connects the elements of a UML model.
It also describes how many objects are taking part in that relationship.
Generalization-
Realization-
What is UML?
Page 39
visualizing, constructing, and documenting the artifacts of the software systems, as
well as for business modeling.
Benefits of UML:
It becomes very much easy for the software programmer to implement the
actual demand once they have a clear picture of the problem.
Class diagram
Object diagram
Sequence diagram
Collaboration diagram
Activity diagram
Deployment diagram
Page 40
Component diagram
Page 41
UML-Relationship
Dependency
Whenever there is a change in either the structure or the behavior of the class that
affects the other class, such a relationship is termed as a dependency. Or, simply,
we can say a class contained in other class is known as dependency. It is a
unidirectional relationship.
Association
Association is a structural relationship that represents how two entities are linked
or connected to each other within a system. It can form several types of
associations, such as one-to-one, one-to-many, many-to-one, and many-to-
many. A ternary association is one that constitutes three links. It portrays the static
relationship between the entities of two classes.
Aggregation
Composition
Page 42
In a composition relationship, the child depends on the parent. It forms a two-way
relationship. It is a special case of aggregation. It is known as Part-of relationship.
Examples A doctor has patients when the doctor gets A hospital and its wards. If the
transfer to another hospital, the patients do hospital is destroyed, the wards also
not accompany to a new workplace. get destroyed.
Generalization
Page 43
Any child can access, update, or inherit the functionality, structure, and behavior of
the parent.
Realization
o Association
o Dependency
o Generalization
o Realization
Association
Example:
Page 44
1) A single teacher has multiple students.
The composition and aggregation are two subsets of association. In both of the
cases, the object of one class is owned by the object of another class; the only
difference is that in composition, the child does not exist independently of its
parent, whereas in aggregation, the child is not dependent on its parent i.e.,
standalone. An aggregation is a special form of association, and composition is the
special form of aggregation.
Page 45
Aggregation
For example:
Here we are considering a car and a wheel example. A car cannot move without a
wheel. But the wheel can be independently used with the bike, scooter, cycle, or
any other vehicle. The wheel object can exist without the car object, which proves
to be an aggregation relationship.
Page 46
Composition
As you can see from the example given below, the composition association
relationship connects the Person class with Brain class, Heart class, and Legs class.
If the person is destroyed, the brain, heart, and legs will also get discarded.
In UML, it can exist between two It is a part of the association relationship. It is a part of the aggregation relationship.
or more classes.
Page 47
It incorporates one-to-one, one- It exhibits a kind of weak relationship. It exhibits a strong type of relationship.
to-many, many-to-one, and many-
to-many association between the
classes.
It can associate one more objects In an aggregation relationship, the In a composition relationship, the associated
together. associated objects exist independently objects cannot exist independently within the
within the scope of the system. scope of the system.
In this, objects are linked In this, the linked objects are independent Here the linked objects are dependent on
together. of each other. each other.
It may or may not affect the other Deleting one element in the aggregation It affects the other element if one of its
associated element if one element relationship does not affect other associated element is deleted.
is deleted. associated elements.
Example: A tutor can associate Example: A car needs a wheel for its Example: If a file is placed in a folder and
with multiple students, or one proper functioning, but it may not require that is folder is deleted. The file residing
student can associate with the same wheel. It may function with inside that folder will also get deleted at the
multiple teachers. another wheel as well. time of folder deletion.
Class Notation
UML class is represented by the following figure. The diagram is divided into four
parts.
The third section is used to describe the operations performed by the class.
Page 48
Classes are used to represent objects. Objects can be anything having properties
and responsibility.
Object Notation
The object is represented in the same way as the class. The only difference is
the name which is underlined as shown in the following figure.
Interface Notation
Page 49
Interface is used to describe the functionality without implementation. Interface is
just like a template where you define different functions, not the implementation.
When a class implements the interface, it also implements the functionality as per
requirement.
Collaboration Notation
Use case is represented as an eclipse with a name inside it. It may contain
additional responsibilities.
Page 50
Use case is used to capture high level functionalities of a system.
Actor Notation
An actor can be defined as some internal or external entity that interacts with the
system.
An actor is used in a use case diagram to describe the internal or external entities.
Initial state is defined to show the start of a process. This notation is used in almost
all diagrams.
The usage of Initial State Notation is to show the starting point of a process.
Page 51
Final state is used to show the end of a process. This notation is also used in almost
all diagrams to describe the end.
The usage of Final State Notation is to show the termination point of a process.
Active class looks similar to a class with a solid border. Active class is generally
used to describe the concurrent behavior of a system.
Component Notation
Component is used to represent any part of a system for which UML diagrams are
made.
Node Notation
Page 52
A node in UML is represented by a square box as shown in the following figure
with a name. A node represents the physical component of the system.
Node is used to represent the physical part of a system such as the server, network,
etc.
Relationships
A model is not complete unless the relationships between elements are described
properly. The Relationship gives a proper meaning to a UML model. Following are
the different types of relationships available in UML.
Dependency
Association
Generalization
Page 53
Extensibility
Dependency Notation
Association Notation
Page 54
Generalization Notation
Extensibility Notation
All the languages (programming or modeling) have some mechanism to extend its
capabilities such as syntax, semantics, etc. UML also has the following
mechanisms to provide extensibility features.
Page 55
Extensibility notations are used to enhance the power of the language. It is
basically additional elements used to represent some extra behavior of the system.
These extra behaviors are not covered by the standard available notations.
Association is the semantic relationship between classes that shows how one
instance is connected or merged with others in a system. The objects are combined
either logically or physically. Since it connects the object of one class to the object
of another class, it is categorized as a structural relationship
Reflexive Association
In the reflexive associations, the links are between the objects of the same classes.
In other words, it can be said that the reflexive association consists of the same
class at both ends. An object can also be termed as an instance.
Let's have a look at its example of a class vegetable. The vegetable class has two
objects, i.e., onion and eggplant. According to the reflexive association's definition,
the link between the onion and eggplant (Brinjal) exist, as they belong to the same
class, i.e., vegetable.
Page 56
Directed Association
The directed association is concerned with the direction of flow inside association
classes. The flow of association can be shown by employing a directed association.
The directed association between two classes is represented by a line with an
arrowhead, which indicates the navigation direction. The flow of association from
one class to another is always in one direction.
It can be said that there is an association between a person and the company. The
person works for the company. Here the person works for the company, and not
the company works for a person.
Page 57
Dependency :-
Dependency depicts how various things within a system are dependent on each
other. In UML, a dependency relationship is the kind of relationship in which a
client (one element) is dependent on the supplier (another element). It is used in
class diagrams, component diagrams, deployment diagrams, and use-case
diagrams, which indicates that a change to the supplier necessitates a change to the
client. An example is given below:
Generalization
The parent model element can have as many children, and also, the child can have
one or more parents. But most commonly, it can be seen that there is one parent
model element and multiple child model elements. The generalization relationship
Page 58
does not consist of names. The generalization relationship is represented by a solid
line with a hollow arrowhead pointing towards the parent model element from the
child model element.
Page 59
Example:
As we know, the bank account can be of two types; Savings Account and Credit
Card Account. Both the savings and the credit card account inherits the generalized
properties from the Bank Account, which is Account Number, Account Balance,
etc.
Realization
In UML modeling, the realization is a relationship between two objects, where the
client (one model element) implements the responsibility specified by the supplier
(another model element). The realization relationship can be employed in class
diagrams and components diagrams.
Page 60
The realization relationship does not have names. It is mostly found in the
interfaces. It is represented by a dashed line with a hollow arrowhead at one end
that points from the client to the server.
Interface Realization
Interface realization is a kind of specialized relation between the classifier and the
interface. In interface realization relationship, realizing classifiers conforms to the
contract defined by the interface.
The interface realization relationship does not contain names, and if you name it,
then the name will appear beside the connector in the diagram.
Class Diagram
Class diagrams are the most common diagrams used in UML. Class diagram
consists of classes, interfaces, associations, and collaboration. Class diagrams
basically represent the object-oriented view of a system, which is static in nature.
Page 61
Active class is used in a class diagram to represent the concurrency of the system.
Class diagram describes the attributes and operations of a class and also the
constraints imposed on the system. The class diagrams are widely used in the
modeling of object oriented systems because they are the only UML diagrams,
which can be mapped directly with object-oriented languages.
UML diagrams like activity diagram, sequence diagram can only give the sequence
flow of the application, however class diagram is a bit different. It is the most
popular UML diagram in the coder community.
Page 62
1. It can represent the object model for complex systems.
2. It reduces the maintenance time by providing an overview of how an
application is structured before coding.
3. It provides a general schematic of an application for better understanding.
4. It represents a detailed chart by highlighting the desired code, which is to be
programmed.
5. It is helpful for the stakeholders and the developers.
o Upper Section: The upper section encompasses the name of the class. A
class is a representation of similar objects that shares the same relationships,
attributes, operations, and semantics. Some of the following rules that
should be taken into account while representing a class are given below:
The attributes are written along with its visibility factors, which are public (+),
private (-), protected (#), and package (~).
Page 63
Relationships
In UML, relationships are of three types:
Page 64
o Association: It describes a static or physical connection between two or
more objects. It depicts how many objects are there in the relationship.
For example, a department is associated with the college.
Page 65
Aggregation: An aggregation is a subset of association, which represents has a
relationship. It is more specific then association. It defines a part-whole or part-of
relationship. In this kind of relationship, the child class can exist independently of
its parent class.
A contact book consists of multiple contacts, and if you delete the contact book, all
the contacts will be lost.
Page 66
Abstract Classes
In the abstract class, no objects can be a direct entity of the abstract class. The
abstract class can neither be declared nor be instantiated. It is used to find the
functionalities across the classes. The notation of the abstract class is similar to that
of class; the only difference is that the name of the class is written in italics. Since
it does not involve any implementation for a given function, it is best to use the
abstract class with multiple objects.
Let us assume that we have an abstract class named displacement with a method
declared inside it, and that method will be called as a drive (). Now, this abstract
class method can be implemented by any object, for example, car, bike, scooter,
cycle, etc.
Class diagrams have a lot of properties to consider while drawing but here the
diagram will be considered from a top level view.
The name of the class diagram should be meaningful to describe the aspect
of the system.
Page 67
Each element and their relationships should be identified in advance.
Use notes whenever required to describe some aspect of the diagram. At the
end of the drawing it should be understandable to the developer/coder.
Finally, before making the final version, the diagram should be drawn on
plain paper and reworked as many times as possible to make it correct.
First of all, Order and Customer are identified as the two elements of the
system. They have a one-to-many relationship because a customer can have
multiple orders.
Order class is an abstract class and it has two concrete classes (inheritance
relationship) SpecialOrder and NormalOrder.
The two inherited classes have all the properties as the Order class. In
addition, they have additional functions like dispatch () and receive ().
The following class diagram has been drawn considering all the points mentioned
above.
Page 68
Page 69
A class diagram describing the sales order system is given below.
Class diagram is also considered as the foundation for component and deployment
diagrams. Class diagrams are not only used to visualize the static view of the
system but they are also used to construct the executable code for forward and
reverse engineering of any system.
Generally, UML diagrams are not directly mapped with any object-oriented
programming languages but the class diagram is an exception.
Page 70
Class diagram clearly shows the mapping with object-oriented languages such as
Java, C++, etc. From practical experience, class diagram is generally used for
construction purpose.
Object Diagram
Object diagrams can be described as an instance of class diagram. Thus, these
diagrams are more close to real-life scenarios where we implement a system.
Object diagrams are a set of objects and their relationship is just like class
diagrams. They also represent the static view of the system.
The usage of object diagrams is similar to class diagrams but they are used to
build prototype of a system from a practical perspective.
Object diagrams are derived from class diagrams so object diagrams are dependent
upon class diagrams.
Object diagrams represent an instance of a class diagram. The basic concepts are
similar for class diagrams and object diagrams. Object diagrams also represent the
static view of a system but this static view is a snapshot of the system at a
particular moment.
Object diagrams are used to render a set of objects and their relationships as an
instance.
Page 71
The difference is that a class diagram represents an abstract model consisting of
classes and their relationships. However, an object diagram represents an instance
at a particular moment, which is concrete in nature.
It means the object diagram is closer to the actual system behavior. The purpose is
to capture the static view of a system at a particular moment.
Page 72
How to Draw an Object Diagram?
We have already discussed that an object diagram is an instance of a class diagram.
It implies that an object diagram consists of instances of things used in a class
diagram.
So both diagrams are made of same basic elements but in different form. In class
diagram elements are in abstract form to represent the blue print and in object
diagram the elements are in concrete form to represent the real world object.
From the above discussion, it is clear that a single object diagram cannot capture
all the necessary instances or rather cannot specify all the objects of a system.
Hence, the solution is −
First, analyze the system and decide which instances have important data
and association.
Second, consider only those instances, which will cover the functionality.
Before drawing an object diagram, the following things should be remembered and
understood clearly −
Page 73
The link in object diagram is used to connect objects.
Objects and links are the two elements used to construct an object diagram.
After this, the following things are to be decided before starting the construction of
the diagram −
The object diagram should have a meaningful name to indicate its purpose.
Customer
Order
SpecialOrder
NormalOrder
Now the customer object (C) is associated with three order objects (O1, O2, and
O3). These order objects are associated with special order and normal order objects
(S1, S2, and N1). The customer has the following three orders with different
numbers (12, 32 and 40) for the particular time considered.
The customer can increase the number of orders in future and in that scenario the
object diagram will reflect that. If order, special order, and normal order objects
are observed then you will find that they have some values.
Page 74
For orders, the values are 12, 32, and 40 which implies that the objects have these
values for a particular moment (here the particular time when the purchase is made
is considered as the moment) when the instance is captured
The same is true for special order and normal order objects which have number of
orders as 20, 30, and 60. If a different time of purchase is considered, then these
values will change accordingly.
The following object diagram has been drawn considering all the points mentioned
above
Now, if you take a snap of the running train then you will find a static picture of it
having the following −
Here, we can imagine the snap of the running train is an object having the above
values. And this is true for any real-life simple or complex system.
Page 75
Object Diagrams are used for −
Reverse engineering.
2. Dynamic changes are not included in the class Dynamic changes are captured in the
diagram. object diagram.
3. The data values and attributes of an instance are It incorporates data values and attributes
not involved here. of an entity.
4. The object behavior is manipulated in the class Objects are the instances of a class.
diagram.
Component Diagram
Component diagrams represent a set of components and their relationships. These
components consist of classes, interfaces, or collaborations. Component diagrams
represent the implementation view of a system.
Page 76
During the design phase, software artifacts (classes, interfaces, etc.) of a system are
arranged in different groups depending upon their relationship. Now, these groups
are known as components.
Thus from that point of view, component diagrams are used to visualize the
physical components in a system. These components are libraries, packages, files,
etc.
A single component diagram cannot represent the entire system but a collection of
diagrams is used to represent the whole.
Page 77
Describe the organization and relationships of the components.
b) A node
Page 78
The component diagrams have remarkable importance. It is used to depict the
functionality and behavior of all the components present in the system, unlike other
diagrams that are used to represent the architecture of the system, working of a
system, or simply the system itself.
Following are some reasons for the requirement of the component diagram:
Page 79
Once the system is designed employing different UML diagrams, and the artifacts
are prepared, the component diagram is used to get an idea of implementation. It
plays an essential role in implementing applications efficiently.
Following are some artifacts that are needed to be identified before drawing a
component diagram:
Following are some points that are needed to be kept in mind after the artifacts are
identified:
1. Using a meaningful name to ascertain the component for which the diagram
is about to be drawn.
In the following diagram, four files are identified and their relationships are
produced. Component diagram cannot be matched directly with other UML
diagrams discussed so far as it is drawn for completely different purpose.
The following component diagram has been drawn considering all the
points mentioned above.
Page 80
Example of a Component Diagram
A component diagram for an online shopping system is given below:
Page 81
Where to Use Component Diagrams?
Page 82
As we have already discussed, those components are libraries, files,
executables, etc. Before implementing the application, these components are
to be organized. This component organization is also designed separately as
a part of project execution.
Deployment Diagram
Deployment diagrams are a set of nodes and their relationships. These nodes are
physical entities where the components are deployed.
Deployment diagrams are used for visualizing the deployment view of a system.
This is generally used by the deployment team.
Page 83
UML is mainly designed to focus on the software artifacts of a system. However,
these two diagrams are special diagrams used to focus on software and hardware
components.
Most of the UML diagrams are used to handle logical components but deployment
diagrams are made to focus on the hardware topology of a system. Deployment
diagrams are used by the system engineers.
The purpose of deployment diagrams can be described as −
Visualize the hardware topology of a system.
Describe the hardware components used to deploy software components.
Describe the runtime processing nodes.
Page 84
How to Draw a Deployment Diagram?
Deployment diagram represents the deployment view of a system. It is related to
the component diagram because the components are deployed using the
deployment diagrams. A deployment diagram consists of nodes. Nodes are
nothing but physical hardware used to deploy the application.
Deployment diagrams are useful for system engineers. An efficient deployment
diagram is very important as it controls the following parameters −
Performance
Scalability
Maintainability
Portability
Before drawing a deployment diagram, the following artifacts should be identified
−
Nodes
Relationships among nodes
Page 85
Following is a sample deployment diagram to provide an idea of the deployment
view of order management system. Here, we have shown nodes as −
Monitor
Modem
Caching server
Server
The application is assumed to be a web-based application, which is deployed in a
clustered environment using server 1, server 2, and server 3. The user connects to
the application using the Internet. The control flows from the caching server to the
clustered environment.
The following deployment diagram has been drawn considering all the points
mentioned above.
Page 86
Example of a Deployment diagram
A deployment diagram for the Apple iTunes application is given below.
The iTunes setup can be downloaded from the iTunes website, and also it can be
installed on the home computer. Once the installation and the registration are
done, iTunes application can easily interconnect with the Apple iTunes store.
Users can purchase and download music, video, TV serials, etc. and cache it in the
media library.
Devices like Apple iPod Touch and Apple iPhone can update its own media
library from the computer with iTunes with the help of USB or simply by
downloading media directly from the Apple iTunes store using wireless protocols,
for example; Wi-Fi, 3G, or EDGE.
Page 87
Where to Use Deployment Diagrams?
Deployment diagrams are mainly used by system engineers. These diagrams are
used to describe the physical components (hardware), their distribution, and
association.
Deployment diagrams can be visualized as the hardware components/nodes on
which the software components reside.
Software applications are developed to model complex business processes.
Efficient software applications are not sufficient to meet the business
requirements. Business requirements can be described as the need to support the
increasing number of users, quick response time, etc.
To meet these types of requirements, hardware components should be designed
efficiently and in a cost-effective way.
Now-a-days software applications are very complex in nature. Software
applications can be standalone, web-based, distributed, mainframe-based and
many more. Hence, it is very important to design the hardware components
efficiently.
Deployment diagrams can be used −
To model the hardware topology of a system.
To model the embedded system.
To model the hardware details for a client/server system.
To model the hardware details of a distributed application.
For Forward and Reverse engineering.
For modeling the embedded system.
Note − If the above descriptions and usages are observed carefully then
it is very clear that all the diagrams have some relationship with one
another. Component diagrams are dependent upon the classes,
interfaces, etc. which are part of class/object diagram. Again, the
deployment diagram is dependent upon the components, which are used
to make component diagrams.
Page 88
Use Case Diagram :-
To model a system, the most important aspect is to capture the dynamic
behavior. Dynamic behavior means the behavior of the system when it
is running /operating.
A Use Case diagram is used to represent the dynamic behavior of a
system. It encapsulates the system's functionality by incorporating use
cases, actors, and their relationships. It models the tasks, services, and
functions required by a system/subsystem of an application. It depicts
the high-level functionality of a system and also tells how the user
handles a system.
Page 89
as other four diagrams (activity, sequence, collaboration, and Statechart)
also have the same purpose. We will look into some specific purpose,
which will distinguish it from other four diagrams.
Use case diagrams are used to gather the requirements of a system
including internal and external influences. These requirements are
mostly design requirements. Hence, when a system is analyzed to gather
its functionalities, use cases are prepared and actors are identified.
When the initial task is complete, use case diagrams are modelled to
present the outside view.
In brief, the purposes of use case diagrams can be said to be as follows −
Used to gather the requirements of a system.
Used to get an outside view of a system.
Identify the external and internal factors influencing the system.
Show the interaction among the requirements are actors.
Use-case:
Page 90
UML UseCase Notation
Actor:
It is used inside use case diagrams. The actor is an entity that interacts
with the system. A user is the best example of an actor. An actor is an
entity that initiates the use case from outside the scope of a use case.
It can be any element that can trigger an interaction with the use case.
One actor can be associated with multiple use cases in the system.
The actor notation in UML is given below.
Page 91
How to Draw a Use Case Diagram?
Use case diagrams are considered for high level requirement analysis of
a system. When the requirements of a system are analyzed, the
functionalities are captured in use cases.
We can say that use cases are nothing but the system functionalities
written in an organized manner. The second thing which is relevant to
use cases are the actors. Actors can be defined as something that
interacts with the system.
Actors can be a human user, some internal applications, or may be some
external applications. When we are planning to draw a use case
diagram, we should have the following items identified.
Functionalities to be represented as use case
Actors
Relationships among the use cases and actors.
Use case diagrams are drawn to capture the functional requirements of a
system. After identifying the above items, we have to use the following
guidelines to draw an efficient use case diagram
The name of a use case is very important. The name should be
chosen in such a way so that it can identify the functionalities
performed.
Give a suitable name for actors.
Show relationships and dependencies clearly in the diagram.
Page 92
Do not try to include all types of relationships, as the main purpose
of the diagram is to identify the requirements.
Use notes whenever required to clarify some important points.
The most significant interactions should be represented among the
multiple no of interactions between the use case and actors.
Page 93
Another Example of a Use Case Diagram
A use case diagram depicting the Online Shopping website is given
below.
Here the Web Customer actor makes use of any online shopping website
to purchase online. The top-level uses are as follows; View Items, Make
Purchase, Checkout, Client Register. The View Items use case is
utilized by the customer who searches and view products. The Client
Register use case allows the customer to register itself with the website
for availing gift vouchers, coupons, or getting a private sale invitation. It
is to be noted that the Checkout is an included use case, which is part
of Making Purchase, and it is not available by itself.
Page 94
The View Items is further extended by several use cases such as; Search
Items, Browse Items, View Recommended Items, Add to Shopping Cart,
Add to Wish list. All of these extended use cases provide some functions
to customers, which allows them to search for an item. The View Items
is further extended by several use cases such as; Search Items, Browse
Items, View Recommended Items, Add to Shopping Cart, Add to Wish
list. All of these extended use cases provide some functions to
customers, which allows them to search for an item.
Both View Recommended Item and Add to Wish List include the
Customer Authentication use case, as they necessitate authenticated
customers, and simultaneously item can be added to the shopping cart
without any user authentication.
Page 95
Similarly, the Checkout use case also includes the following use cases,
as shown below. It requires an authenticated Web Customer, which can
be done by login page, user authentication cookie ("Remember me"), or
Single Sign-On (SSO). SSO needs an external identity provider's
participation, while Web site authentication service is utilized in all
these use cases.
The Checkout use case involves Payment use case that can be done
either by the credit card and external credit payment services or with
PayPal.
Page 96
Important tips for drawing a Use Case diagram
Following are some important tips that are to be kept in mind while
drawing a use case diagram:
1. A simple and complete use case diagram should be articulated.
2. A use case diagram should represent the most significant
interaction among the multiple interactions.
3. At least one module of a system should be represented by the use
case diagram.
Page 97
4. If the use case diagram is large and more complex, then it should
be drawn more generalized.
Where to Use a Use Case Diagram?
To understand the dynamics of a system, we need to use different types
of diagrams. Use case diagram is one of them and its specific purpose is
to gather system requirements and actors.
Use case diagrams specify the events of a system and their flows. But
use case diagram never describes how they are implemented. Use case
diagram can be imagined as a black box where only the input, output,
and the function of the black box is known.
These diagrams are used at a very high level of design. This high level
design is refined again and again to get a complete and practical picture
of the system. A well-structured use case also describes the pre-
condition, post condition, and exceptions. These extra elements are used
to make test cases when performing the testing.
Although use case is not a good candidate for forward and reverse
engineering, still they are used in a slightly different way to make
forward and reverse engineering. The same is true for reverse
engineering. Use case diagram is used differently to make it suitable for
reverse engineering.
In forward engineering, use case diagrams are used to make test cases
and in reverse engineering use cases are used to prepare the requirement
details from the existing application.
Use case diagrams can be used for −
Requirement analysis and high level design.
Model the context of a system.
Page 98
Reverse engineering.
Forward engineering.
Page 99
An example of use case diagram for Bank ATM subsystem - top level use
cases.
On most bank ATMs, the customer is authenticated by inserting a plastic
ATM card and entering a personal identification number
(PIN). Customer Authentication use case is required for every ATM
transaction so we show it as <<include>> relationship. Including this use
case as well as transaction generalizations make the ATM
Transaction an abstract use case.
Page 100
Bank ATM Transactions and Customer Authentication Use Cases
Example.
Customer may need some help from the ATM. ATM Transaction use
case is <<extended>> via extension point called menu by the ATM
Help use case whenever ATM Transaction is at the location specified by
the menu and the bank customer requests help, e.g. by selecting Help
menu item.
Page 101
Bank ATM Maintenance, Repair, Diagnostics Use Cases Example.
ATM Technician maintains or repairs Bank ATM. Maintenance use case
includes Replenishing ATM with cash, ink or printer paper, Upgrades of
hardware, firmware or software, and remote or on-site Diagnostics.
Another example of a use-case diagram
Following use case diagram represents the working of the student
management system:
Page 102
well as test marks on the application or a system. This actor can perform
only these interactions with the system even though other use cases are
remaining in the system.
It is not necessary that each actor should interact with all the use cases,
but it can happen.
The second actor named teacher can interact with all the functionalities
or use cases of the system. This actor can also update the attendance of a
student and marks of the student. These interactions of both student and
teacher actor together sums up the entire student management
application.
When to use a use-case diagram?
A use case is a unique functionality of a system which is accomplished
by a user. A purpose of use case diagram is to capture core
functionalities of a system and visualize the interactions of various
things called as actors with the use case. This is the general use of a use
case diagram.
The use case diagrams represent the core parts of a system and the
workflow between them. In use case, implementation details are hidden
from the external use only the event flow is represented.
With the help of use case diagrams, we can find out pre and post
conditions after the interaction with the actor. These conditions can be
determined using various test cases.
In general use case diagrams are used for:
1. Analyzing the requirements of a system
2. High-level visual software designing
Page 103
3. Capturing the functionalities of a system
4. Modeling the basic idea behind the system
5. Forward and reverse engineering of a system using various test
cases.
Use cases are intended to convey desired functionality so the exact scope
of a use case may vary according to the system and the purpose of
creating UML model.
Summary
Use case diagrams are a way to capture the system's functionality
and requirements in UML diagrams.
It captures the dynamic behavior of a live system.
A use case diagram consists of a use case and an actor.
A use case represents a distinct functionality of a system, a
component, a package, or a class.
An actor is an entity that initiates the use case from outside the
scope of a use case.
The name of an actor or a use case must be meaningful and
relevant to the system.
A purpose of use case diagram is to capture the core functionalities
of a system.
Page 104
Activity Diagrams :-
Activity diagram is another important diagram in UML to describe the
dynamic aspects of the system.
Activity diagram is basically a flowchart to represent the flow from one
activity to another activity. The activity can be described as an
operation of the system.
The control flow is drawn from one operation to another. This flow can
be sequential, branched, or concurrent. Activity diagrams deal with all
type of flow control by using different elements such as fork, join, etc
Page 105
Describe the parallel, branched and concurrent flow of the system.
Page 106
Conditions
Constraints
Once the above-mentioned parameters are identified, we need to make a
mental layout of the entire flow. This mental layout is then transformed
into an activity diagram.
Following are the rules that are to be followed for drawing an activity
diagram:
1. A meaningful name should be given to each and every activity.
2. Identify all of the constraints.
3. Acknowledge the activity associations.
Activities
Page 107
Activity partition /swimlane
The swimlane is used to cluster all the related activities in one column or
one row. It can be either vertical or horizontal. It used to add modularity
to the activity diagram. It is not necessary to incorporate swimlane in the
activity diagram. But it is used to add more transparency to the activity
diagram.
Forks
Forks and join nodes generate the concurrent flow inside the activity. A
fork node consists of one inward edge and several outward edges. It is
the same as that of various decision parameters. Whenever a data is
received at an inward edge, it gets copied and split crossways various
outward edges. It split a single inward flow into multiple parallel flows.
Page 108
Join Nodes
Join nodes are the opposite of fork nodes. A Logical AND operation is
performed on all of the inward edges as it synchronizes the flow of input
across one single output (outward) edge.
Page 109
Activity diagram constitutes following notations:
Final State: It is the stage where all the control flows and object flows
end.
Decision Box: It makes sure that the control flow or object flow will
follow only one path.
Page 110
Where to Use Activity Diagrams?
The basic usage of activity diagram is similar to other four UML
diagrams. The specific usage is to model the control flow from one
activity to another. This control flow does not include messages.
Activity diagram is suitable for modeling the activity flow of the system.
An application can have multiple systems. Activity diagram also
captures these systems and describes the flow from one system to
another. This specific usage is not available in other diagrams. These
systems can be database, external queues, or any other system.
We will now look into the practical applications of the activity diagram.
From the above discussion, it is clear that an activity diagram is drawn
from a very high level. So it gives high level view of a system. This high
level view is mainly for business users or any other person who is not a
technical person.
This diagram is used to model the activities which are nothing but
business requirements. The diagram has more impact on business
understanding rather than on implementation details.
Activity diagram can be used for −
Modeling work flow by using activities.
Modeling business requirements.
High level understanding of the system's functionalities.
Investigating business requirements at a later stage.
Page 111
When to use an Activity Diagram?
An activity diagram can be used to portray business processes and
workflows. Also, it used for modeling business as well as the software.
An activity diagram is utilized for the followings:
1. To graphically model the workflow in an easier and
understandable way.
2. To model the execution flow among several activities.
3. To model comprehensive information of a function or an algorithm
employed within the system.
4. To model the business process and its workflow.
5. To envision the dynamic aspect of a system.
6. To generate the top-level flowcharts for representing the workflow
of an application.
7. To represent a high-level view of a distributed or an object-
oriented system.
Page 112
Example of Activity Diagram
Let us consider mail processing activity as a sample for Activity
Diagram. Following diagram represents activity for processing e-mails.
Page 113
In the above activity diagram, three activities are specified. When the
mail checking process begins user checks if mail is important or junk.
Two guard conditions [is essential] and [is junk] decides the flow of
execution of a process. After performing the activity, finally, the process
is terminated at termination node.
Following is an example of an activity diagram for order management
system. In the diagram, four activities are identified which are associated
with conditions. One important point should be clearly understood that
an activity diagram cannot be exactly matched with the code. The
activity diagram is made to understand the flow of activities and is
mainly used by the business users
Following diagram is drawn with the four main activities −
Send order by the customer
Receipt of the order
Confirm the order
Dispatch the order
After receiving the order request, condition checks are performed to
check if it is normal or special order. After the type of order is identified,
dispatch activity is performed and that is marked as the termination of
the process.
Page 114
An example of an activity diagram showing the business flow activity of
order processing is given below.
Here the input parameter is the Requested order, and once the order is
accepted, all of the required information is then filled, payment is also
accepted, and then the order is shipped. It permits order shipment before
an invoice is sent or payment is completed.
Page 115
3.2.3 Sequence Diagram :-
The sequence diagram represents the flow of messages in the system and is also
termed as an event diagram. It helps in envisioning several dynamic scenarios. It
portrays the communication between any two lifelines as a time-ordered sequence
of events, such that these lifelines took part at the run time. In UML, the lifeline is
represented by a vertical bar, whereas the message flow is represented by a vertical
dotted line that extends across the bottom of the page. It incorporates the iterations
as well as branching.
Page 116
Notations of a Sequence Diagram
Lifeline
Actor
A role played by an entity that interacts with the subject is called as an actor. It is
out of the scope of the system. It represents the role, which involves human users
and external hardware or subjects. An actor may or may not represent a physical
entity, but it purely depicts the role of an entity. Several distinct roles can be
played by an actor or vice versa.
Page 117
Activation
Page 118
Messages
The messages depict the interaction between the objects and are represented by
arrows. They are in the sequential order on the lifeline. The core of the sequence
diagram is formed by messages and lifelines.
Page 119
o Self Message: It describes a communication, particularly between the
lifelines of an interaction that represents a message of the same lifeline, has
been invoked.
Page 120
o Create Message: It describes a communication, particularly between the
lifelines of an interaction describing that the target (lifeline) has been
instantiated.
Page 121
Note
Sequence Fragments
Page 122
Types of fragments
Following are the types of fragments enlisted below;
alt Alternative multiple fragments: The only fragment for which the condition is true, will execute.
opt Optional: If the supplied condition is true, only then the fragments will execute. It is similar to
alt with only one trace.
loop Loop: Fragments are run multiple times, and the basis of interaction is shown by the guard.
region Critical region: Only one thread can execute a fragment at once.
Page 123
ref Reference: An interaction portrayed in another diagram. In this, a frame is drawn so as to
cover the lifelines involved in the communication. The parameter and return value can be
explained.
Example :-
Page 124
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.
Example 1:-
The sequence diagram has four objects (Customer, Order, SpecialOrder and
NormalOrder).
The following diagram shows the message sequence for SpecialOrder object and
the same can be used in case of NormalOrder object. It is important to understand
the time sequence of message flows. The message flow is nothing but a method
call of an object.
The first call is sendOrder () which is a method of Order object. The next call
is confirm () which is a method of SpecialOrder object and the last call is Dispatch
() which is a method of SpecialOrder object. The following diagram mainly
describes the method calls from one object to another, and this is also the actual
scenario when the system is running.
Page 125
Sequence diagram Example 2:-
1. Place an order.
3. Order Confirmation.
4. Order preparation.
5. Order serving.
Page 126
If one changes the order of the operations, then it may result in crashing the
program. It can also lead to generating incorrect 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.
Any online customer can search for a book catalog, view a description of a
particular book, add a book to its shopping cart, and do checkout.
Page 127
Benefits of a Sequence Diagram
Sequence diagrams are used to represent message flow from one object to
another object.
Page 128
Sequence diagram allows reverse as well as forward engineering.
Sequence diagrams can become complex when too many lifelines are
involved in the system.
The type of message decides the type of sequence inside the diagram.
Page 129
Notations of a Collaboration Diagram
Following are the components of a component diagram that are enlisted below:
o In the collaboration diagram, firstly, the object is created, and then its
class is specified.
2. Actors: In the collaboration diagram, the actor plays the main role as it
invokes the interaction. Each actor has its respective role and name. In this,
one actor initiates the use case.
Page 130
When to use a Collaboration Diagram?
The collaborations are used when it is essential to depict the relationship between
the object. Both the sequence and collaboration diagrams represent the same
information, but the way of portraying it quite different. The collaboration
diagrams are best suited for analyzing use cases.
Following are some of the use cases enlisted below for which the collaboration
diagram is implemented:
3. To capture the interactions that represent the flow of messages between the
objects and the roles inside the collaboration.
Page 131
4. To model different scenarios within the use case or operation, involving a
collaboration of several objects and interactions.
2. Discover the structural elements that are class roles, objects, and subsystems
for performing the functionality of collaboration.
Page 132
Example of a Collaboration Diagram
Method calls are similar to that of a sequence diagram. However, difference being
the sequence diagram does not describe the object organization, whereas the
collaboration diagram shows the object organization.
Page 133
Following diagram represents the sequencing over student management system:
Page 134
The above collaboration diagram represents a student information management
system. The flow of communication in the above diagram is given by,
7. It focuses on the elements and not the message flow, like sequence
diagrams.
8. Since the collaboration diagrams are not that expensive, the sequence
diagram can be directly converted to the collaboration diagram.
Page 135
The drawback of a Collaboration Diagram:-
1. Multiple objects residing in the system can make a complex collaboration
diagram, as it becomes quite hard to explore the objects.
2. It is a time-consuming diagram.
The state machine diagram is also called the Statechart or State Transition
diagram, which shows the order of states underwent by an object within the
Page 136
system. It captures the software system's behavior. It models the behavior of a
class, a subsystem, a package, and a complete system.
It tends out to be an efficient way of modeling the interactions and collaborations
in the external entities and the system. It models event-based systems to handle the
state of an object. It also defines several distinct states of a component within the
system. Each object/component has a specific state.
Purpose of Statechart Diagrams :-
Statechart diagram is one of the five UML diagrams used to model the dynamic
nature of a system. They define different states of an object during its lifetime and
these states are changed by events. Statechart diagrams are useful to model the
reactive systems. Reactive systems can be defined as a system that responds to
external or internal events.
Statechart diagram describes the flow of control from one state to another state.
States are defined as a condition in which an object exists and it changes when
some event is triggered. The most important purpose of Statechart diagram is
to model lifetime of an object from creation to termination.
Statechart diagrams are also used for forward and reverse engineering of a system.
However, the main purpose is to model the reactive system.
Following are the types of a state machine diagram that are given below:-
1. Behavioral state machine
The behavioral state machine diagram records the behavior of an object
within the system. It depicts an implementation of a particular entity. It
models the behavior of the system.
Page 137
the change in the state of the protocol and parallel changes within the
system. But it does not portray the implementation of a particular
component. (Protocol = Procedure/etiquette / code of behavior /set of Rules)
It blueprints an interactive system that response back to either the internal events or
the external ones. The execution flow from one state to another is represented by a
state machine diagram. It visualizes an object state from its creation to its
termination.
Page 138
Initial state: It defines the initial state (beginning) of a system, and it is
represented by a black filled circle.
Final state: It represents the final state (end) of a system. It is denoted by a filled
circle present within a circle.
Transition: A change of control from one state to another due to the occurrence of
some event is termed as a transition. It is represented by an arrow labeled with an
event due to which the change has ensued.
Types of State
Page 139
2. Composite state: It consists of nested states (sub-states), such that it does
not contain more than one initial state and one final state. It can be nested to
any level.
It portrays the changes underwent by an object from the start to the end. It
basically envisions how triggering an event can cause a change within the system.
Statechart diagrams are very important for describing the states. States can be
identified as the condition of objects when a particular event occurs.
Page 140
Identify the important objects to be analyzed.
The primary focus of the state machine diagram is to depict the states of a system.
These states are essential while drawing a state transition diagram. The objects,
states, and events due to which the state transition occurs must be acknowledged
before the implementation of a state machine diagram.
Following are the steps that are to be incorporated while drawing a state machine
diagram:
Initially, the ATM is turned off. After the power supply is turned on, the ATM
starts performing the startup action and enters into the Self Test state. If the test
fails, the ATM will enter into the Out Of Service state, or it will undergo a
triggerless transition to the Idle state. This is the state where the customer waits
for the interaction.
Page 141
Whenever the customer inserts the bank or Credit/Debit card in the ATM's card
reader, the ATM state changes from Idle to Serving Customer, the entry
action readCard is performed after entering into Serving Customer state. Since
the customer can cancel the transaction at any instant, so the transition
from Serving Customer state back to the Idle state could be triggered
by cancel event.
Here the Serving Customer is a composite state with sequential substates that
are Customer Authentication, Selecting Transaction, and Transaction.
Page 142
Following is an example of a Statechart diagram where the state of Order
object is analyzed:-
The first state is an idle state from where the process starts. The next states are
arrived for events like send request, confirm request, and dispatch order. These
events are responsible for the state changes of order object.
During the life cycle of an object (here order object) it goes through the following
states and there may be some abnormal exits. This abnormal exit may occur due to
some problem in the system. When the entire life cycle is complete, it is
considered as a complete transaction as shown in the following figure. The initial
and final state of an object is also shown in the following figure.
Page 143
Example of State Machine
Following state diagram example chart represents the user authentication process.
Page 144
UML state diagram
There are a total of two states, and the first state indicates that the OTP has to be
entered first. After that, OTP is checked in the decision box, if it is correct, then
only state transition will occur, and the user will be validated. If OTP is incorrect,
then the transition will not take place, and it will again go back to the beginning
state until the user enters the correct OTP as shown in the above state machine
diagram example.
Page 145
State Machine Flowchart
It encompasses the concept of WAIT, i.e., wait for an event or It does not constitute the concept of WAIT.
an action.
It is concerned with several states of a system. It focuses on control flow and path.
Case Study1
Library Management System
Problem Statement:
The case study titled Library Management System is library management software
for the purpose of monitoring and controlling the transactions in a library. This
case study on the library management system gives us the complete information
about the library and the daily transactions done in a Library. We need to maintain
the record of new s and retrieve the details of books available in the library which
mainly focuses on basic operations in a library like adding new member, new
books, and up new information, searching books and members and facility to
borrow and return books. It features a familiar and well thought-out, an attractive
user interface, combined with strong searching, insertion and reporting capabilities.
The report generation facility of library system helps to get a good idea of which
are ths borrowed by the members, makes users possible to generate hard copy.
Page 146
The following are the brief description on the functions achieved through this case
study:
End-Users:
•Librarian: To maintain and update the records and also to cater the needs of the
users.
•Reader: Need books to read and also places various requests to the librarian.
•Vendor: To provide and meet the requirement of the prescribed books.
Class Diagram
Classes identified:
Library
Librarian
Books Database
User
Vendor
Page 147
Use-case Diagram
Librarian:-
•Issue a book
•Track complaints
Page 148
User:-
•Register
•Login
•Search a book
•View history
•Unregister
Books Database :-
•Update records
Vendors
•Provide books to the library
•Payment acknowledgement
Page 149
Sequence Diagram
Sequence diagram for searching a book and issuing it as per the request by the user
from the librarian:
Page 150
Collaboration Diagram
Collaboration Diagram for searching a book and issuing it as per the request by the
user from the librarian:
Page 151
Activity Diagram
Activities:
Page 152
State Chart Diagram
States:
Authentication
Successfully logged on or re-login
Search for a book (user) / request the vendor (librarian) / provide the requested
book (vendor)
Receive acknowledgement
Transitions:
Page 153
Logged in ---> Search <---> Acknowledgement
Component Diagram
Components:
Page 154
Logout Page (user / librarian / vendor)
Deployment Diagram
Systems Used:
Local Consoles / Computers for login and search purposes by users, librarian and
vendors.
Library LAN Server interconnecting all the systems to the Database.
Internet to provide access to Vendors to supply the requested books by the
Librarian.
Vendor Server to maintain the records of the requests made by the librarian and
books provided to the library.
Page 155
Case Study2
Online Mobile Recharge
Problem Statement:
The case study 'Online Mobile Recharge' gives us the information about all the
mobile service providers. This application provides us the complete information
regarding any mobile service provider in terms of their plans, options, benefits, etc.
Suppose, any Airtel customer wants to have the information of all the schemes and
services provided by the company, he/she can have the information and according
to his convenience he can recharge the mobile from the same application. The
major advantage of this proposed system is to have the recharging facility of any
service provider under same roof.
Page 156
End users:
Service Provider:
Service Provider is the one who is nothing but the mobile service provider like all
the companies who are giving the mobile connections come under this module.
Functionality of this module is to make the mobile recharging of their company
basing on the availability of balance in the admin account. Request comes from the
user and it is going to be verified at the admin for the availability of balance and
then the request is forwarded to the service provided to make the mobile recharge.
Administrator is the one who monitors all users and user transactions. Admin also
monitors all the Service Providers, all the user accounts, and amounts paid by the
user and amounts paid to Service providers. When the request given by the user
admin checks the available balance in the user account then request is forwarded to
the Service Provider from there user request gets processed. Admin haves the
complete information related to user and all the information related to the schemes
and other information of different recharge coupons provided by the Service
Providers. All the data is maintained at the Admin level. Admin is having the
rights to restrict any user.
User:
There are 2 categories in the user Module:
Page 157
•Visitor
Any person who wants to utilize the services of Online Mobile Recharge at any
time from any where they should get registered in this application. After getting
registered user can recharge the mobile at any time and from any where. Visitor is
the one who visits the Online Mobile Recharge application and have the complete
information related to the Service Providers and can make the mobile recharge by
entering the bank details or by giving the credit card details.
Class Diagram
Classes Identified:
Service Provider
Direct or Non- Third Party User (Direct access through Service Provider Site)
Page 158
Use-Case Diagram
User:-
•Register.
•Recharge.
•Select Payment Gateway.
•Make payment.
Page 159
•Track Complaints.
Service Provider:-
•Recharge the user requested either directly or through the third party system.
•Provide various plans to the user.
Page 160
Sequence Diagram
Sequence Diagram for a user to recharge his account through third party site:
Page 161
Collaboration Diagram
Collaboration diagram for a user to recharge his account through third arty site:
Activity Diagram
Activities:
Page 162
Login and authenticate Bank Account.
Make payment.
Page 163
State Chart Diagram
States:
Operator Selection
Request recharge
•Payment made
Logged off.
Transitions:
Logged in ---> Operator Selection ---> Tariff Plans <---> Request Recharge
Page 164
Component Diagram
Components:
Third Party Home Page (visitor / registered user / admin / service provider)
Service Provider Home Page (visitor / registered user / admin / service provider)
Page 165
Deployment Diagram
Systems Used:
1)Consoles / Computers for registration, login purposes by third party users and for
quick recharge by direct users.
2)Third Party Server to receive and respond to all the requests from various users.
3)Internet to provide access to users to recharge their accounts through payment
gateways by placing requests through Third Party Sites and Service Providers sites.
4)Payment Gateway Server like Bank's server to provide online payment through
their personal accounts to meet the requirements of the users.
5)Service Provider Server to maintain the records of the requests made by the
users.
Page 166
Page 167