You are on page 1of 63

Learning Resource

On

Software Engineering

Chapter-7
Software Design: Object Oriented Design using
UML

Prepared By:
Kunal Anand, Asst. Professor
SoCE, KIIT, DU, Bhubaneswar-24
Organization of the Chapter

• Introduction to Object Oriented Design


• Overview of Object-Oriented Concepts
• Unified Modeling Language (UML)
• UML Diagrams
• Examples
• Summary

27 October 2022 2
Introduction to Object Oriented Design
• Object Oriented Design (OOD) is another popular design
approach followed in software development process.

• In OOD, the entire system is viewed as a collection of objects.

• All possible objects are identified in the proposed system.

• Further, data and possible operations, are identified for each


object along with the relationship among the objects.

• The modeling of the object-oriented system is based on a


special type of language, known as UML.

27 October 2022 3
Overview of Object-Oriented Concepts
• In object-oriented concepts, following key concepts are used:
– Object
– Class
– Message and methods
– Abstraction
– Encapsulation
– Inheritance
– Polymorphism
– Message binding
– Genericity

27 October 2022 4
Object Oriented Concepts (contd..)
• Object:
– Any real-world entity can be considered as an object.

– Each object consists of some data and a set of operations,


referred to as methods, that can be applied on that object.

– An object can access only its own data using its methods.
However, it can interact with other objects in order to
perform some task.

– It is easy to understand when the system is analyzed,


developed and implemented in terms of natural objects.
27 October 2022 5
Object Oriented Concepts (contd..)
• Class:
– Class is a collection of similar kind of objects. i.e., objects
with similar properties and behavior represents a class.
– In actual, objects exist whereas class is just a theoretical
concept.
– In a library management system, one of the objects is
“Library member”.
• For the object “library member”, the data can be
member_name, member_id, address, phone_no,
date_of_join etc.
• Similarly, the methods can be issue_book,
find_book_outstanding, find_book_overdue, ret_book
etc.
27 October 2022 6
Object Oriented Concepts (contd..)
• Methods and Messages: Operations supported by an object,
are called methods.
– The methods of an object are invoked by sending message
to it.
– The set of messages to an object constitutes its protocol.

• Inheritance: This feature allows to define a new class


(derived class) by extending or modifying an existing class
(base class).
– The inheritance can be viewed as
“generalization-specialization” relationship.
– The derived class inherits the properties from its base class.
Additionally, it also has its own properties.
27 October 2022 7
Inheritance

• Inheritance is a must for any object-oriented language. It


encourages code reuse.
27 October 2022 8
Object Oriented Concepts (contd..)
• Abstract class:
– The class, for which objects can not be created, is known as abstract
class.
– They serve as a skeleton structure based on which other classes can
be derived and used.
• Abstraction:
– It is a mechanism that allows us to focus on a certain portion by
omitting the irrelevant details.
– It allows the developers to understand the problem better.
– It reduces the complexity of the software that ultimately increases
software productivity.
• Encapsulation:
– This property allows the object to interact with the outer world only
through messages. The outer world don’t have any idea about “how
the objects are implemented”.
27 October 2022 9
Object Oriented Concepts (contd..)
• Polymorphism:
– It allows the objects to use the same message at different
times to perform different operations, as per the
requirement.
– Here, multiple operations are defined using same name. It
adds the advantage of code reuse.
– Dynamic binding allows to add new derived objects to the
existing objects, with minimal changes.

• Composite Objects:
– Objects that contain other objects are called composite
objects. They can be used to realize complex behavior.

27 October 2022 10
Related terms
• Persistent objects:
– The permanently stored objects are known as persistent objects.
They live across different execution.
– It can be done by keeping a copy of object in secondary storage.
• Agents:
– They are known as active objects.
– They monitor events occurring in the application and act
autonomously.
– They are used in applications like monitoring exceptions.
• Widget:
– Widget stands for “window object”. It is a primitive object used in
UML.
– It maintains internal data. The methods supported by a widget
manipulate the stored data and carry out operations.

27 October 2022 11
Advantages of OOD
• Code and design reuse
• Increased productivity
• Ease of testing and maintenance
• Better understandability
• Cost effective
– A functioning and well-established object-oriented
methodology and environment is likely to be managed with
20-50% of the cost of the traditional development.

27 October 2022 12
Unified Modeling Language
• Unified Modeling Language, UML, provides a set of notations
to create models of a system.

• These models are useful in documenting the design and result


analysis.

• UML is a graphical representation of a real time system using


different diagrams, known as UML diagrams.

• UML was developed to standardize the large number of object


-oriented modeling notations that existed and were extensively
used in early 90s.

27 October 2022 13
UML Diagrams
• UML diagrams can capture following five views of a system:
– User's view:
• This view defines the functionalities made available by
the system to its users.
• It captures the external view of a system i.e., how a user
sees the system from outside.
• The user's view is considered as “black box” view
where the users don’t have any idea about “how the
system is working”. They can only use the system
without knowing its internal structure.
• The diagram under user's view is known as use case
diagram.

27 October 2022 14
UML Diagrams (contd..)
• Structural View:
– It defines the objects that are important to the
understanding of the working of a system, and its
implementation.
– It also captures the relationship among the objects.
– Diagrams: object diagram, class diagram

• Behavioral View:
– It captures the interactions among the objects to realize the
overall system behavior.
– Diagrams: sequence diagram, activity diagram, state-chart
diagram, collaboration diagram

27 October 2022 15
UML Diagrams (contd..)

• Implementation view:
– This view captures the important components and their
dependencies.
– Diagram: Component diagram

• Environmental view:
– This view models how the different components of the
system are implemented on a different piece of hardware.
– Diagram: Deployment diagram

27 October 2022 16
Use Case Diagram
• In UML, a use case diagram can summarize the details of the
system's users (also known as actors).
• Use case diagrams are ideal for:
– Representing the goals of system-user interactions
– Defining and organizing functional requirements in a
system
– Specifying the context and requirements of a system
– Modeling the basic flow of events in a use case

• An effective use case diagram can help your team discuss and
represent scenarios in which the system or application interacts
with people, organizations, or external systems

27 October 2022 17
Use Case Diagram (contd..)
• A use case diagram, usually have following components:
– Actors: Stick figures that represent the people employing
the use cases.

– Use cases: Horizontally shaped ovals that represent the


different uses that a user might have.

– Relationships: To represent the relationships between an


actor and use case, or between two use cases. A line or
arrow is used to represent the relationships.

– System boundary boxes: A box that sets a system scope to


use cases. All use cases outside the box would be
considered outside the scope of that system.
27 October 2022 18
Relationship in Use Case Diagram
• There can be following relationship types in a use case
diagram.
– Association between actors and use cases
– Extend between two use cases
– Include between two use cases
– Generalization of a use case

• Association Between Actor and Use Case


– This one is straightforward and present in every use case
diagram. A line is used to represent association.
– An actor must be associated with at least one-use case.
– An actor can be associated with multiple use cases.
– Multiple actors can be associated with a single use case.
27 October 2022 19
Association Between Actor and Use Case

27 October 2022 20
Generalization
• In generalization relationship, the behavior of the ancestor is
inherited by the descendant.
• This is used when there is common behavior between two use
cases and specialized behavior specific to each use case.
• For example, there might be a generalized use case called
“Pay Bills”. This can be extended to specific use cases like
“Pay by Card”, “Pay by Net banking”, “Pay by UPI” etc.

Pay Bill Pay by UPI

Pay by Pay by net Pay by


card banking wallet

27 October 2022 21
Include Relationship
• Include relationship shows that the behavior of the included
use case, is part of the including (base) use case.
• The main reason for this is, to reuse the common actions
across multiple use cases. In some situations, this is done to
simplify complex behaviors. Few things to consider when
using the <<include>> relationship.
• The base use case is incomplete without the included use case.
The included use case is mandatory and not optional.

27 October 2022 22
Extend Relationship
• The extend relationship allows to show the optional system
behavior.
• Extend relationship is shown as a dashed line with an open
arrowhead directed from the extending use case to the
extended (base) use case. The arrow is labeled with the
keyword «extend».
• The extend use case can add additional behavior only at an
extension point when certain conditions are satisfied.
• Registration use case is complete and meaningful on its own. It
could be extended with optional “Get Help On Registration”
use case.

27 October 2022 23
Use Case Diagram (contd..)
• Problem Title: ATM Application: In general, the interaction
between a user and bank ATM machine happens as below:
– A user logs into the system. This login is authenticated by the
bank administration. The login may result in either successful
login or FAILED login. In case of successful login, the user is
navigated to the TRANSACTION option. However, The user
gets the INCORRECT PIN message and prompted to enter the
correct PIN, in case of FAILED login.
– User is offered with different options available under
TRANSACTION. These options include BALANCE CHECK,
WITHDRAWL, DEPOSIT, FUNDS TRANSFER and other
services. All these options can be performed by the user but only
one at a time. The bank administration authenticates these
transactions option.
– The ATM system is maintained by an IT team which mainly
includes SYSTEM MAINTENANCE and REPORT
27 October 2022
GENERATION work. 24
Solution
• Actors: USER, BANK and IT Team

• Use Cases: Login, Transaction, Bad PIN, Balance,


Withdrawal, Deposit, Fund transfer, Other services,
Maintenance, System Maintenance and Report generation.

• Relationships:
– Actors USER and BANK is associated to LOGIN
– BANK is also associated to Transaction.
– Transaction includes BALANCE CHECK, WITHDRAWL,
DEPOSIT, FUNDS TRANSFER and other services.
– Actor IT team is associated to Maintenance which includes
SYSTEM MAINTENANCE (SM) and REPORT
GENERATION (RG).
27 October 2022 25
Use Case Diagram for ATM Application

27 October 2022 26
Class Diagram
• Class diagram is a graphical representation of the static view
of the system and represents different aspects of the
application.

• A collection of class diagrams represent the whole system.

• The purpose of the class diagram can be summarized as:


– Analysis and design of the static view of an application.
– Describe responsibilities of a system.
– Base for component and deployment diagrams.
– Forward and reverse engineering.

27 October 2022 27
Class Diagram
• The following points should be remembered while drawing a
class diagram:
– The name of the class diagram should be meaningful to
describe the aspect of the system.
– Each element and their relationships should be identified in
advance.
– Responsibility (attributes and methods) of each class
should be clearly identified
– For each class, minimum number of properties should be
specified, as unnecessary properties will make the diagram
complicated.
– 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.
27 October 2022 28
An Example: Loan_Account
• In the example, a class called “loan_account” is depicted.
Classes in class diagrams are represented by boxes that are
partitioned into three:
– The top partition contains the name of the class.
– The middle part contains the class’s attributes.
– The bottom partition shows the possible operations that are
associated with the class.

27 October 2022 29
Relationship in Class Diagram
• In a class diagrams, the classes are interrelated to each other in
following relationships:
– Association: Any logical connection between two classes.

– Directed Association refers to a directional relationship represented by


a line with an arrowhead. The arrowhead depicts a container-contained
directional flow, along with cardinality.

27 October 2022 30
contd..
• Aggregation:
– Aggregation is a special type of association where the
involved classes support “whole-part” relationship
between them.
– It is a weak type of association.
– Here, the contained class is not strongly dependent on the
container class.
– Aggregation is represented by an empty diamond symbol at
the aggregate end of a relationship.

27 October 2022 31
contd..
• Composition:
– It is also a whole/part relationship. It is a stricter form of aggregation,
in which the “part” is existence dependent on “whole”.
– In composition, there is a strong relationship between the container
and contained classes. The contained class will lose its significance if
the container class is deleted.
– Composition relationship is denoted using a straight line with a filled
diamond drawn at the composite end.

• Aggregation vs Composition:
– If components can be added to or removed from the aggregate, then
the relationship is aggregation. On the other hand, if the
components are not required to be added/deleted dynamically, then
the relationship is composition.
27 October 2022 32
contd..
• Inheritance:
– It refers to a type of
relationship wherein one
associated class is a child of
another by virtue of assuming
the same functionalities of
the parent class.
– In other words, the child class
is a specific type of the parent
class.
– To show inheritance in a
UML diagram, a solid line
from the child class to the
parent class is drawn using an
unfilled arrowhead.

27 October 2022 33
Class Diagram for ATM Application
• Problem Description: An ATM application can be described as below:
– A Bank, with a branch code and location, maintains and manages
various customers and ATMs.
– A Customer has to provide basic personal information like name, date
of birth and address to their bank. The customers can have one or more
accounts in the bank. The bank issues debit card to each of its
customers. A customer can perform one or many transaction using the
debit card by visiting the bank ATM.
– An Account can be either Savings or PPF account with the details like
account number, account balance and it supports two functions named
as deposit and withdraw. Additionally, PPF account also has a maturity
date.
– The ATMs are assigned with unique ID and are situated at different
locations. The ATM is managed by the bank. ATM identifies
customers and performs the transactions opted by them.
– Every Transaction has unique transaction ID, date of transaction, type
of transaction, amount and balance after transaction. The ATM
transaction updates the customer account after successful completion of
27 October 2022 34
the transaction.
contd..

27 October 2022 35
Object Diagram
• A class diagram represents an abstract model consisting of
classes and their relationship.
• An object diagram shows a snapshot/instance of the objects in
a system at a point in time. It is also known as instance
diagram.
• It captures the static view of a system at a particular moment.
• The purpose of the object diagram can be summarized as:
– Forward and reverse engineering.
– Object relationships of a system
– Static view of an interaction.
– Understand object behavior and their relationship from
practical perspective

27 October 2022 36
Notations used in Object Diagram
• Object Notation:
– The object we create represents an entity which exists in the system.
– We can represent the changes in object over time by creating
multiple instance specifications.
– We use a rectangle to represent an object in an Object Diagram. An
object is generally linked to other objects in an object diagram.

27 October 2022 37
contd..
• Links – We use a link to represent a relationship between two
objects.

• Dependency Relationships – We use a dependency


relationship to show when one element depends on another
element.

• Association
• Aggregation
• Composition

27 October 2022 38
Object Diagram
• To capture a particular system, numbers of class diagrams are
limited. However, if we consider object diagrams then we can
have unlimited number of instances, which are unique in
nature. Only those instances are considered, which have an
impact on the system.
• 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.
– Third, make some optimization as the number of instances
are 2022
27 October unlimited. 39
Object Diagram
• 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.
– The most important elements are to be identified.
– The association among objects should be clarified.
– Values of different elements need to be captured to include
in the object diagram.

27 October 2022 40
Sample Example

27 October 2022 41
Activity Diagram
• 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 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.
• The purpose of an activity diagram can be described as:
– Draw the activity flow of a system.
– Describe the sequence from one activity to another.
– Describe the parallel, branched and concurrent flow of the
system.
27 October 2022 42
Activity Diagram
• Activity diagrams are not exactly flowcharts as they have
some additional capabilities. These additional capabilities
include branching, parallel flow, swim lane, etc.
• The main element of an activity diagram is the activity itself.
• An activity is a function performed by the system. After
identifying the activities, we need to understand how they are
associated with constraints and conditions.
• Before drawing an activity diagram, we should identify the
following elements:
– Activities
– Association
– Conditions
– Swim lanes

27 October 2022 43
Sample Example: Withdrawal from ATM

27 October 2022 44
State-chart Diagram
• It describes different states of a component in a system. The
states are specific to a component/object of a system.

• A State-chart diagram describes a state machine that defines


different states of an object that can be controlled by external
or internal events.

• State-chart diagrams are useful to model the reactive systems


as these systems respond to external or internal events.

27 October 2022 45
State-chart Diagram
• State-chart 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 State-chart diagram is to model
lifetime of an object from creation to termination.
• Following are the main purposes of using State-chart diagrams
– To model the dynamic aspect of a system.
– To model the life time of a reactive system.
– To describe different states of an object during its life time.
– Define a state machine to model the states of an object.

27 October 2022 46
Example: Withdrawal from ATM

27 October 2022 47
Interaction Diagrams
• This interactive behavior is represented in UML by two
diagrams known as Sequence diagram and Collaboration
diagram.

• Sequence diagram emphasizes on time sequence of messages


and collaboration diagram emphasizes on the structural
organization of the objects that send and receive messages.

• Sequence and collaboration diagrams are used to capture the


dynamic nature but from a different angle.

27 October 2022 48
Interaction Diagrams
• The purpose of interaction diagram is:
– To describe the message flow in the system.
– To describe the structural organization of the objects.
– To describe the interaction among objects.

• 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.

27 October 2022 49
Sequence Diagram

27 October 2022 50
Collaboration Diagram
• In the collaboration diagram, the method call sequence is
indicated by some numbering technique.

• Method calls are similar to that of a sequence diagram. The


number indicates how the methods are called one after
another.

• To choose between these two diagrams, emphasis is placed on


the type of requirement.
– If the time sequence is important, then the sequence
diagram is used.
– If organization is required, then collaboration diagram is
used.
27 October 2022 51
Collaboration Diagram

27 October 2022 52
Component Diagram
• Component diagram is a special kind of diagram in UML. It
does not describe the functionality of the system but it
describes the components used to make those functionalities.
• Component diagrams can also be described as a static
implementation view of a system. Static implementation
represents the organization of the components at a particular
moment.
• They are used:
– to model the physical aspects of a system; such as
executables, libraries, files, documents, etc. which reside in
a node.
– to visualize the organization and relationships among
components in a system. These diagrams are also used to
make executable systems.
27 October 2022 53
Component Diagram
• Before drawing a component diagram, the following artifacts
are to be identified clearly:
– Files used in the system.
– Libraries and other artifacts relevant to the application.
– Relationships among the artifacts.

• After identifying the artifacts, the following points need to be


kept in mind.
– Use a meaningful name to identify the component for
which the diagram is to be drawn.
– Prepare a mental layout before producing the using tools.
– Use notes for clarifying important points.

27 October 2022 54
Component Diagram

27 October 2022 55
Deployment Diagram
• Deployment diagrams are used to describe the static
deployment view of a system.

• Deployment diagrams consist of nodes and their relationships.

• Deployment diagrams are used to visualize the topology of the


physical components of a system, where the software
components are deployed.

• Component diagrams and deployment diagrams are closely


related.

27 October 2022 56
Deployment Diagram
• 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
27 October 2022 57
Deployment Diagram

27 October 2022 58
Object Oriented Design Pattern
• A pattern serves as a guide to create good design.
• A pattern has following four components:
– Problem
– Context in which problem occurs
– Solution
– Context in which the solution works.
• Some important patterns are as below:
– Expert
– Creator
– Controller
– Facade
– Model view separation
– Intermediary
27 October 2022 59
Design Patterns
• Expert:
– Problem: Which class should be responsible for doing
certain things?
– Solution: the class that has the necessary information to do
the job.
• Creator:
– Problem: Which class should be responsible for creating
new instance for a class?
– Solution: A class C1 can create an instance of class C2, if:
• C1 is an aggregation of objects of type C2
• C1 contains object of type C2
• C1 closely uses objects of type C2
• C1 has the data required to initialize the objects of type C2, when
they are created.
27 October 2022 60
Design Patterns
• Controller
– Problem: Who should be handling actor requirement?
– Solution: For every use case, a separate controller object.
• Facade
– Problem: How should the services be requested from a
service package?
– Solution: A class can be created which provides a common
interface to the services of the package.
• Model View Separation
– Problem: How should the non GUI classes communicate
with GUI classes?
– Solution: It says that the model objects should not have the
direct knowledge to the view object.
27 October 2022 61
Design Patterns
• Intermediary
– Problem: How should the client and server object interact
with each other?
– Solution:
• A proxy object, at the client side, can be defined which
is a local sit-in for the remore server object.
• This proxy is responsible for determining the server
address, communicating the server address, obtaining
the server response and passing that to the client.
• The proxy could have the same interface as the server so
that the client feels as if it is interacting directly with the
sever.

27 October 2022 62
Object Oriented Analysis and Design
• It refers to the method of developing an initial model of the
software from SRS document.
• The analysis model is refined into a design model that can be
implemented using a suitable object oriented programming
language.

GUI Use
Interacti
Prototy Case
on
pe Diagram
Diagram
Star
t
Cod
e

SRS Domain Class


Model Diagram
27 October 2022 Glossar 63
y

You might also like