Object Oriented Software Engineering Unit - 4
Object Oriented Software Engineering Unit - 4
The class diagram depicts a static view of an application. It represents the types of objects residing
in the system and the relationships between them. A class consists of its objects, and also it may
inherit from other classes. A class diagram is used to visualize, describe, document various
different aspects of the system, and also construct executable software code.
It shows the attributes, classes, functions, and relationships to give an overview of the software
system. It constitutes class names, attributes, and functions in a separate compartment that helps
in software development. Since it is a collection of classes, interfaces, associations, collaborations,
and constraints, it is termed as a structural diagram.
The main purpose of class diagrams is to build a static view of an application. It is the only diagram
that is widely used for construction, and it can be mapped with object-oriented languages. It is one
of the most popular UML diagrams. Following are the purpose of class diagrams given below:
1. It analyses and designs a static view of an application.
2. It describes the major responsibilities of a system.
3. It is a base for component and deployment diagrams.
4. It incorporates forward and reverse engineering.
o Middle Section: The middle section constitutes the attributes, which describe the quality
of the class. The attributes have the following characteristics:
. The attributes are written along with its visibility factors, which are public (+), private (-),
protected (#), and package (~).
a. The accessibility of an attribute class is illustrated by the visibility factors.
b. A meaningful name should be assigned to the attribute, which will explain its usage
inside the class.
o Lower Section: The lower section contain methods or operations. The methods are
represented in the form of a list, where each method is written in a single line. It
demonstrates how a class interacts with data.
Visibility
Visibility allows to constrain the usage of a named element, either in namespaces or in
access to the element. It is used with classes, packages, generalizations, element
import, package import.
Note, that if a named element is not owned by any namespace, then it does not have a visibility.
A public element is visible to all elements that can access the contents of
the namespace that owns it. Public visibility is represented by '+' literal.
Access for each of these visibility types is shown below for members of different classes.
Access Right public (+) private (-) protected (#) Package (~)
Members of the same class Yes Yes yes yes
Members of derived classes Yes No yes yes
Members of any other class Yes No no in same package
Multiplicity
Multiplicity in class diagram should be indicated at each end of the association. This
specifies the minimum and maximum number of instances that can be linked.
For example, a car has 3 or 4 wheels, but each wheel belongs to exactly one car. Place
multiplicity notations near the ends of an association. These symbols indicate the number of
instances of one class linked to one instance of the other class.
For example, one company will have one or more employees, but each employee works for one
company only.
The minimum and maximum values are separated by two dots.
An asterisk (*) represents an indeterminate maximum value.
In the case that the minimum and maximum values are the same, the number is displayed only
once.
In addition, zero or more (0… *) is also referred to as a simple asterisk (*) because it is
common.
Finally, ranges and/or individual values can be separated by commas to list alternative values,
i.e. 1..3, 5..8
2. Directed Association
A directed association in a UML class diagram represents a relationship between two
classes where the association has a direction, indicating that one class is associated with
another in a specific way.
In a directed association, an arrowhead is added to the association line to indicate the
direction of the relationship. The arrow points from the class that initiates the association to
the class that is being targeted or affected by the association.
Directed associations are used when the association has a specific flow or directionality,
such as indicating which class is responsible for initiating the association or which class
has a dependency on another.
Consider a scenario where a “Teacher” class is associated with a “Course” class in a
university system. The directed association arrow may point from the “Teacher” class to the
“Course” class, indicating that a teacher is associated with or teaches a specific course.
The source class is the “Teacher” class. The “Teacher” class initiates the association by
teaching a specific course.
The target class is the “Course” class. The “Course” class is affected by the association as
it is being taught by a specific teacher.
3. Aggregation
Aggregation is a specialized form of association that represents a “whole-part” relationship. It
denotes a stronger relationship where one class (the whole) contains or is composed of another
class (the part). Aggregation is represented by a diamond shape on the side of the whole class.
In this kind of relationship, the child class can exist independently of its parent class.
Let’s understand aggregation using an example:
The company can be considered as the whole, while the employees are the parts. Employees
belong to the company, and the company can have multiple employees. However, if the
company ceases to exist, the employees can still exist independently.
4. Composition
Composition is a stronger form of aggregation, indicating a more significant ownership or
dependency relationship. In composition, the part class cannot exist independently of the
whole class. Composition is represented by a filled diamond shape on the side of the whole
class.
Let’s understand Composition using an example:
Imagine a digital contact book application. The contact book is the whole, and each contact
entry is a part. Each contact entry is fully owned and managed by the contact book. If the
contact book is deleted or destroyed, all associated contact entries are also removed.
This illustrates composition because the existence of the contact entries depends entirely on the
presence of the contact book. Without the contact book, the individual contact entries lose their
meaning and cannot exist on their own.
5. Generalization (Inheritance)
Inheritance represents an “is-a” relationship between classes, where one class (the
subclass or child) inherits the properties and behaviors of another class (the superclass or
parent). Inheritance is depicted by a solid line with a closed, hollow arrowhead pointing from
the subclass to the superclass.
In the example of bank accounts, we can use generalization to represent different types of
accounts such as current accounts, savings accounts, and credit accounts.
The Bank Account class serves as the generalized representation of all types of bank accounts,
while the subclasses (Current Account, Savings Account, Credit Account) represent
specialized versions that inherit and extend the functionality of the base class.
6. Realization (Interface Implementation)
Realization indicates that a class implements the features of an interface. It is often
used in cases where a class realizes the operations defined by an interface. Realization is
depicted by a dashed line with an open arrowhead pointing from the implementing class to the
interface.
Let’s consider the scenario where a “Person” and a “Corporation” both realizing an “Owner”
interface.
Owner Interface: This interface now includes methods such as “acquire (property)” and
“dispose (property)” to represent actions related to acquiring and disposing of property.
Person Class (Realization): The Person class implements the Owner interface, providing
concrete implementations for the “acquire (property)” and “dispose (property)” methods.
For instance, a person can acquire ownership of a house or dispose of a car.
Corporation Class (Realization): Similarly, the Corporation class also implements the
Owner interface, offering specific implementations for the “acquire (property)” and
“dispose (property)” methods. For example, a corporation can acquire ownership of real
estate properties or dispose of company vehicles.
Both the Person and Corporation classes realize the Owner interface, meaning they provide
concrete implementations for the “acquire (property)” and “dispose (property)” methods
defined in the interface.
7. Dependency Relationship
A dependency exists between two classes when one class relies on another, but the
relationship is not as strong as association or inheritance. It represents a more loosely coupled
connection between classes. Dependencies are often depicted as a dashed arrow.
Consider a scenario where a “Car” class depends on a “FuelTank” class to manage fuel
consumption.
The “Car” class may need to access methods or attributes of the “FuelTank” class to check
the fuel level, refill fuel, or monitor fuel consumption.
In this case, the “Car” class has a usage dependency on the “FuelTank” class because it
utilizes its services to perform certain tasks related to fuel management.
Object diagrams in UML are depicted using a simple and intuitive notations to show a
snapshot of a system at a specific point in time, displaying instances of classes and their
relationships.
What is an Object?
An object refers to a specific instance of a class within a system. A class is a blueprint or
template that defines the common attributes and behaviors shared by a group of objects. An
object, on the other hand, is a concrete and individual occurrence of that class, possessing
unique values for its attributes.
What is a Classifier?
In UML a classifier refers to a group of elements that have some common features like
methods, attributes and operations. A classifier can be thought of as an abstract meta class
which draws a boundary for a group of instances having common static and dynamic features.
For example:
We refer a class, a component, or a deployment node as classifiers in UML since they define a
common set of properties. We are able to design object diagrams by instantiating classifiers.
3. Link
We use a link to represent a relationship between two objects. We represent the number
of participants on the link for each, at the end of the link. The term link is used to specify a
relationship between two instance specifications or objects. We use a solid line to represent a
link between two objects.
For Example – In the figure below, an object of class Student is linked to an object of class
College.
4. Dependency Relationships
We use a dependency relationship to show when one element depends on another element.
A dependency is used to depict the relationship between dependent and independent entities in
the system.
Any change in the definition or structure of one element may cause changes to the other.
This is a unidirectional kind of relationship between two objects.
Dependency relationships are of various types specified with keywords like Abstraction,
Binding, Realization, Substitution and Usage are the types of dependency relationships
used in UML.
For example – In the figure below, an object of Player class is dependent (or uses) an object
of Bat class.
5. Association
Association is a reference relationship between two objects (or classes). An association
line connects two object boxes, representing a relationship between instances of two classes.
We use association when one object references members of the other object. Association can
be uni-directional or bi-directional. We use an arrow to represent association.
For example – The object of Order class is associated with an object of Customer class.
6. Aggregation
Aggregation represents a “has a” or ‘whole-part’ relationship. We use a hollow diamond
on the containing object with a line which joins it to the contained object.
Aggregation is a specific form of association.
It is a kind of parent-child relationship however it isn’t inheritance.
Aggregation occurs when the lifecycle of the contained objects does not strongly depend on
the lifecycle of container objects.
For example – A library has an aggregation relationship with books. Library has books or
books are a part of library. The existence of books is independent of the existence of
the library.
7. Composition
Composition is a type of association where the child cannot exist independent of the
other. We use a filled diamond on the containing object with a line which joins it to the
contained object. Composition is also a special type of association. It is also a kind of parent
child relationship but it is not inheritance. So whenever independent existence of the child is
not possible we use a composition relationship.
Consider the example of a boy Gurkaran: Gurkaran is composed of legs and arms.
Here Gurkaran has a composition relationship with his legs and arms. Here legs and arms
can’t exist without the existence of their parent object.
5. Purpose of Object Diagrams
The main purpose of using object diagrams is:
They offer a detailed view of how objects interact with each other in specific scenarios.
Proper design and analysis of applications can be faster and efficient.
Object diagrams are beneficial during the implementation phase of software development.
Promoting a shared understanding of specific instances and their relationships, facilitating
collaboration among team members.
1. Aggregation
2. Composition
3. Derived Properties
4. Interfaces and Abstract Classes
5. Multiple Classification
6. Association Class
7. Enumeration
8. Active Class
9. Visibility
Note: Where Aggregation, Composition and Visibility are explained in the above content.
Please refer to it.
3. Derived Properties
Derived properties can be calculated based on other values. When we think about a date
range (Figure 5.5), we can think of three properties: the start date, the end date, and the number
of days in the period. These values are linked, so we can think of the length as being derived
from the other two values.
Figure 5.5. Derived attribute in a time period
If you have an abstract class or method, the UML convention is to italicize the name of
the abstract item. You can use the {abstract} constraint, as well (or instead).
Java provides an interface construct, and the compiler checks that the implementing class
provides implementations of all of the interface's operations
In Figure 6-11, we see InputStream, DataInput, and DataInputStream (defined in the
standard [Link] package). InputStream is an abstract class; DataInput is an interface.
Figure 6-11. Interfaces and Abstract Class: An Example from Java
Some client class, say, OrderReader, needs to use DataInput's functionality. The
DataInputStream class implements both the DataInput and InputStream interfaces and is a
subclass of the latter.
The link between DataInputStream and DataInput is a realization relationship.
Realization is deliberately similar to generalization; it indicates that one class implements
behavior specified by another. It is permissible for one implementation class to realize another;
this means that the realizing class must conform to the interface, but need not use inheritance.
In a specification model, there is no difference between realization and subtyping.
The link between OrderReader and DataInput is a dependency. In this case, the dependency
indicates that if the DataInput interface changes, the OrderReader may also have to change. One
of the aims of development is to keep dependencies to a minimum so that the effects of changes
are minimized. Figure 6-12 shows an alternative, more compact notation. Here, the interfaces are
represented by small circles (often called lollipops) coming off the classes that implement them.
Figure 6-12. Lollipop Notation for Interfaces
4. Multiple Classification
Classification refers to the relationship between an object and its type. Mainstream
programming languages assume that an object belongs to a single class. But there are
more options to classification than that.
In single classification, an object belongs to a single type, which may inherit from super-
types. In multiple classification, an object may be described by several types that are not
necessarily connected by inheritance.
Multiple classification is different from multiple inheritance. Multiple inheritance says
that a type may have many super-types but that a single type must be defined for each
object. Multiple classification allows multiple types for an object without defining a
specific type for the purpose.
For example, consider a person subtyped as either man or woman, doctor or nurse,
patient or not (see Figure 5.11). Multiple classification allows an object to have any of
these types assigned to it in any allowable combination, without the need for types to be
defined for all the legal combinations.
Figure 5.11. Multiple classification
If you use multiple classification, you need to be sure that you make it clear which
combinations are legal. UML 2 does this by placing each generalization relationship into
a generalization set. On the class diagram, you label the generalization arrowhead with
the name of the generalization set, which in UML 1 was called the discriminator.
Generalization sets are by default disjoint: Any instance of the super-type may be an
instance of only one of the subtypes within that set. If you roll up generalizations into a
single arrow, they must all be part of the same generalization set, as shown in Figure
5.11. Alternatively, you can have several arrows with the same text label.
To illustrate, note the following legal combinations of subtypes in the diagram: (Female,
Patient, Nurse); (Male, Physiotherapist); (Female, Patient); and (Female, Doctor,
Surgeon). The combination (Patient, Doctor, Nurse) is illegal because it contains two
types from the role generalization set.
6. Association Class
Association classes allow you to add attributes, operations, and other features to
associations, as shown in Figure 5.12. We can see from the diagram that a person may
attend many meetings. We need to keep information about how awake that person was;
we can do this by adding the attribute attentiveness to the association.
Figure 5.12. Association class
Figure 5.13 shows another way to represent this information: Make Attendance a full
class in its own right. Note how the multiplicities have moved.
Figure 5.13. Promoting an association class to a full class
What benefit do you gain with the association class to offset the extra notation you have
to remember? The association class adds an extra constraint, in that there can be only one
instance of the association class between any two participating objects.
7. Enumerations
Enumeration is a useful concept in programming that refers to creating datasets or lists
of related data values. Enumerations are helpful in programming to make our code readable and
understandable by classifying similar data in a single enumeration.
Enumeration representation
We represent the enumeration in UML by a rectangle with two sections:
The enumeration name and the data section.
Enumeration in a class diagram
<<enumeration>>: The keyword mandatory to use in the enumeration to make it
different from the other classes.
EnumerationName: The name of the enumeration.
value1, value2, value3: The distinct data values of the enumeration also known as
enumeration literals.
Example
Let's consider an example of an enumeration for storing the types of a task based on its current
status. The name of the enumeration is TaskStatus, consisting of enumeration literals: Pending,
InProgress, and Completed.
Now let's understand how we can associate this enumeration with an attribute of a class.
In the above diagram, we have a class Task, containing three public attributes: name, dueDate,
and status. The status attribute can have any one of the values present in the enumeration
TaskStatus. We connect our enumeration with the Task class using an association.
We can define an enumeration inside a UML class using the following UML representation.
Now we can directly define the enumeration values for the status attribute in the Task class using
a containment relationship.
By concluding, the enumeration in UML class diagrams offers a powerful tool for
representing distinct values within a class structure. With enumerations, UML class diagrams
become clearer, helping us design and build our software systems efficiently.
8. Active Class
An active class has instances, each of which executes and controls its own thread of
control. Method invocations may execute in a client's thread or in the active object's
thread. A good example of this is a command processor that accepts command objects
from the outside and then executes the commands within its own thread of control.
The notation for active classes has changed from UML 1 to UML 2, as shown in Figure
5.21. In UML 2, an active class has extra vertical lines on the side; in UML 1, it had a
thick border and was called an active object.
Figure 5.21. Active class
From the term Interaction, it is clear that the diagram is used to describe some type of
interactions among the different elements in the model. This interaction is a part of dynamic
behavior of the system.
The purpose of interaction diagrams is to visualize the interactive behavior of the system.
Visualizing the interaction is a difficult task. Hence, the solution is to use different types of
models to capture the different aspects of the interaction.
Sequence and collaboration diagrams are used to capture the dynamic nature but from a
different angle.
We have two types of interaction diagrams in UML. One is the sequence diagram and the
other is the collaboration diagram. The sequence diagram captures the time sequence of the
message flow from one object to another and the collaboration diagram describes the organization
of objects in a system taking part in the message flow.
Following things are to be identified clearly before drawing the interaction diagram
Objects taking part in the interaction.
Message flows among the objects.
The sequence in which the messages are flowing.
Object organization.
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.
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.
Activation
It is represented by a thin rectangle on the lifeline. It describes that time period in which
an operation is performed by an element, such that the top and the bottom of the rectangle is
associated with the initiation and the completion time, each respectively.
Messages
1. Synchronous messages
A synchronous message waits for a reply before the interaction can move forward. The
sender waits until the receiver has completed the processing of the message. The caller
continues only when it knows that the receiver has processed the previous message i.e. it
receives a reply message.
A large number of calls in object oriented programming are synchronous.
We use a solid arrow head to represent a synchronous message.
2. Asynchronous Messages
An asynchronous message does not wait for a reply from the receiver. The interaction moves
forward irrespective of the receiver processing the previous message or not. We use a lined
arrow head to represent an asynchronous message.
3. Create message
We use a Create message to instantiate a new object in the sequence diagram. There are
situations when a particular message call requires the creation of an object. It is represented
with a dotted arrow and create word labelled on it to specify that it is the create Message
symbol.
For example:
The creation of a new order on a e-commerce website would require a new object of Order
class to be created.
4. Delete Message
We use a Delete Message to delete an object. When an object is deallocated memory or is
destroyed within the system we use the Delete Message symbol. It destroys the occurrence of
the object in the system. It is represented by an arrow terminating with a x.
For example:
In the scenario below when the order is received by the user, the object of order class can be
destroyed.
5. Self Message
Certain scenarios might arise where the object needs to send a message to itself. Such
messages are called Self Messages and are represented with a U shaped arrow.
Another example:
Consider a scenario where the device wants to access its webcam. Such a scenario is
represented using a self message.
6. Recursive Message: A self-message sent for recursive purpose is called a recursive message.
In other words, it can be said that the recursive message is a special case of the self-message as it
represents the recursive calls.
7. Reply Message
Reply messages are used to show the message being sent from the receiver to the
sender. We represent a return/reply message using an open arrow head with a dotted line.
The interaction moves forward only when a reply message is sent by the receiver.
For example:
Consider the scenario where the device requests a photo from the user. Here the message
which shows the photo being sent is a reply message.
8. Found Message
A Found message is used to represent a scenario where an unknown source sends the
message. It is represented using an arrow directed towards a lifeline from an end point.
For example:
Consider the scenario of a hardware failure.
It can be due to multiple reasons and we are not certain as to what caused the hardware failure.
9. Lost Message
A Lost message is used to represent a scenario where the recipient is not known to the
system. It is represented using an arrow directed towards an end point from a lifeline.
For example:
Consider a scenario where a warning is generated.
The warning might be generated for the user or other software/object that the lifeline is
interacting with. Since the destination is not known before hand, we use the Lost Message
symbol.
10. Guards
To model conditions we use guards in UML. They are used when we need to restrict the
flow of messages on the pretext of a condition being met. Guards play an important role in
letting software developers know the constraints attached to a system or a particular process.
For example:
In order to be able to withdraw cash, having a balance greater than zero is a condition that
must be met as shown below.
11. Duration Message: It describes a communication particularly between the lifelines of an
interaction, which portrays the time passage of the message while modeling a system.
Note
A note is the capability of attaching several remarks to the element. It basically carries useful
information for the modelers.
The above sequence diagram depicts the sequence diagram for an emotion based music player:
1. Firstly the application is opened by the user.
2. The device then gets access to the web cam.
3. The webcam captures the image of the user.
4. The device uses algorithms to detect the face and predict the mood.
5. It then requests database for dictionary of possible moods.
6. The mood is retrieved from the database.
7. The mood is displayed to the user.
8. The music is requested from the database.
9. The playlist is generated and finally shown to the user.
Sequence Fragments
1. Sequence fragments have been introduced by UML 2.0, which makes it quite easy for the
creation and maintenance of an accurate sequence diagram.
2. It is represented by a box called a combined fragment, encloses a part of interaction inside
a sequence diagram.
3. The type of fragment is shown by a fragment operator.
Types of fragments
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.
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.
Following are the components of a component diagram that are enlisted below:
1. Objects: The representation of an object is done by an object symbol with its name and
class underlined, separated by a colon.
In the collaboration diagram, objects are utilized in the following ways:
o The object is represented by specifying their name and class.
o It is not mandatory for every class to appear.
o A class may constitute more than one object.
o In the collaboration diagram, firstly, the object is created, and then its class is
specified.
o To differentiate one object from another object, it is necessary to name them.
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.
3. Links: The link is an instance of association, which associates the objects and actors. It
portrays a relationship between the objects through which the messages are sent. It is
represented by a solid line. The link helps an object to connect with or navigate to another
object, such that the message flows are attached to links.
4. Messages: It is a communication between objects which carries information and includes
a sequence number, so that the activity may take place. It is represented by a labeled arrow,
which is placed near a link. The messages are sent from the sender to the receiver, and the
direction must be navigable in that particular direction. The receiver must understand the
message.
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:
1. To model collaboration among the objects or roles that carry the functionalities of use cases
and operations.
2. To model the mechanism inside the architectural design of the system.
3. To capture the interactions that represent the flow of messages between the objects and the
roles inside the collaboration.
4. To model different scenarios within the use case or operation, involving a collaboration of
several objects and interactions.
5. To support the identification of objects participating in the use case.
6. In the collaboration diagram, each message constitutes a sequence number, such that the
top-level message is marked as one and so on. The messages sent during the same call are
denoted with the same decimal prefix, but with different suffixes of 1, 2, etc. as per their
occurrence.
The state machine diagram is also called the State Chart or State Transition diagram, which
shows the order of states underwent by an object within the 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.
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.
2. Protocol state machine
It captures the behavior of the protocol. The protocol state machine depicts 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.
Why State Machine Diagram?
Since it records the dynamic view of a system, it portrays the behavior of a software
application. During a lifespan, an object underwent several states, such that the lifespan exist until
the program is executing. Each state depicts some useful information about the object.
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.
The main purpose is to depict each state of an individual object. It represents an interactive
system and the entities inside the system. It records the dynamic behavior of the system.
a. Initial state: It defines the initial state (beginning) of a system, and it is represented by a
black filled circle.
b. Final state: It represents the final state (end) of a system. It is denoted by a filled circle
present within a circle.
c. Decision box: It is of diamond shape that represents the decisions to be made on the basis
of an evaluated guard.
d. 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.
e. State box: It depicts the conditions or circumstances of a particular object of a class at a
specific point of time. A rectangle with round corners is used to represent the state box.
Types of State
The state machine diagram is used to portray various states underwent by an object. The
change in one state to another is due to the occurrence of some event. All of the possible states of
a particular component must be identified before drawing a state machine diagram.
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:
1. A unique and understandable name should be assigned to the state transition that describes
the behavior of the system.
2. Out of multiple objects, only the essential objects are implemented.
3. A proper name should be given to the events and the transitions.
The state machine diagram implements the real-world models as well as the object-oriented
systems. It records the dynamic behavior of the system, which is used to differentiate between the
dynamic and static behavior of a system.
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.
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 trigger less transition to the idle state.
This is the state where the customer waits for the interaction.
Whenever the customer inserts the bank or credit 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 sub-states that
are Customer Authentication, Selecting Transaction, and Transaction.
Customer Authentication and Transaction are the composite states itself is displayed by
a hidden decomposition indication icon. After the transaction is finished, the Serving
Customer encompasses a trigger less transition back to the Idle state. On leaving the state, it
undergoes the exit action ejectCard that discharges the customer card.
It encompasses the concept of WAIT, i.e., wait for an It does not constitute the concept of WAIT.
event or an action.
It is concerned with several states of a system. It focuses on control flow and path.
In UML, the activity diagram is used to demonstrate the flow of control within the system
rather than the implementation. It models the concurrent and sequential activities.
The activity diagram helps in envisioning the workflow from one activity to another. It put
emphasis on the condition of flow and the order in which it occurs. The flow can be sequential,
branched, or concurrent, and to deal with such kinds of flows, the activity diagram has come up
with a fork, join, etc.
Activities
The categorization of behavior into one or more actions is termed as an activity. In other
words, it can be said that an activity is a network of nodes that are connected by edges. The edges
depict the flow of execution. It may contain action nodes, control nodes, or object nodes.
The control flow of activity is represented by control nodes and object nodes that illustrates
the objects used within an activity. The activities are initiated at the initial node and are terminated
at the final node.
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.
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.
Pins
It is a small rectangle, which is attached to the action rectangle. It clears out all the messy
and complicated thing to manage the execution flow of activities. It is an object node that precisely
represents one input to or output from the action.
Initial State: It depicts the initial stage or beginning of the set of actions.
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.
It mainly models processes and workflows. It envisions the dynamic behavior of the system
as well as constructs a runnable system that incorporates forward and reverse engineering. It does
not include the message part, which means message flow is not represented in an activity diagram.
It is the same as that of a flowchart but not exactly a flowchart itself. It is used to depict
the flow between several activities.
Since it incorporates swim-lanes, branching, parallel flows, join nodes, control nodes, and
forks, it supports exception handling. A system must be explored as a whole before drawing an
activity diagram to provide a clearer view of the user. All of the activities are explored after they
are properly analyzed for finding out the constraints applied to the activities. Each and every
activity, condition, and association must be recognized.
After gathering all the essential information, an abstract or a prototype is built, which is
then transformed into the actual 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.
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.
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.
A component diagram is used to break down a large object-oriented system into the smaller
components, so as to make them more manageable. It models the physical view of a system such
as executables, files, libraries, etc. that resides within the node.
It visualizes the relationships as well as the organization between the components present in
the system. It helps in forming an executable system. A component is a single unit of the system,
which is replaceable and executable. The implementation details of a component are hidden, and
it necessitates an interface to execute a function. It is like a black box whose behavior is explained
by the provided and required interfaces.
Notation of a Component Diagram
a) A component
b) A node
Since it is a special kind of a UML diagram, it holds distinct purposes. It describes all the
individual components that are used to make the functionalities, but not the functionalities of the
system. It visualizes the physical components inside the system. The components can be a library,
packages, files, etc.
The component diagram also describes the static view of a system, which includes the
organization of components at a particular instant. The collection of component diagrams
represents a whole system.
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.
In UML, the component diagram portrays the behavior and organization of components at
any instant of time. The system cannot be visualized by any individual component, but it can be
by the collection of components.
Following are some reasons for the requirement of the component diagram:
1. It portrays the components of a system at the runtime.
2. It is helpful in testing a system.
3. It envisions the links between several connections.
The component diagram is helpful in representing the physical aspects of a system, which
are files, executables, libraries, etc. The main purpose of a component diagram is different from
that of other diagrams. It is utilized in the implementation phase of any application.
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:
1. What files are used inside the system?
2. What is the application of relevant libraries and artifacts?
3. What is the relationship between the artifacts?
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.
2. Before producing the required tools, a mental layout is to be made.
3. To clarify the important points, notes can be incorporated.
Example of a Component Diagram
The component diagram is a special purpose diagram, which is used to visualize the static
implementation view of a system. It represents the physical components of a system, or we can
say it portrays the organization of the components inside a system. The components, such as
libraries, files, executables, etc. are first needed to be organized before the implementation.
The deployment diagram visualizes the physical hardware on which the software will be
deployed. It portrays the static deployment view of a system. It involves the nodes and their
relationships.
It ascertains how software is deployed on the hardware. It maps the software architecture
created in design to the physical system architecture, where the software will be executed as a
node. Since it involves many nodes, the relationship is shown by utilizing communication paths.
The main purpose of the deployment diagram is to represent how software is installed on
the hardware component. It depicts in what manner a software interacts with hardware to perform
its execution.
Both the deployment diagram and the component diagram are closely interrelated to each
other as they focus on software and hardware components. The component diagram represents the
components of a system, whereas the deployment diagram describes how they are actually
deployed on the hardware.
The deployment diagram does not focus on the logical components of the system, but it
put its attention on the hardware topology.
The deployment diagram portrays the deployment view of the system. It helps in
visualizing the topological view of a system. It incorporates nodes, which are physical hardware.
The nodes are used to execute the artifacts. The instances of artifacts can be deployed on the
instances of nodes.
Since it plays a critical role during the administrative process, it involves the following parameters:
1. High performance
2. Scalability
3. Maintainability
4. Portability
5. Easily understandable
One of the essential elements of the deployment diagram is the nodes and artifacts. So it is
necessary to identify all of the nodes and the relationship between them. It becomes easier to
develop a deployment diagram if all of the nodes, artifacts, and their relationship is already known.
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.
When to use a Deployment Diagram?
The software applications are quite complex these days, as they are standalone, distributed,
web-based, etc. So, it is very necessary to design efficient software.