Professional Documents
Culture Documents
RAMAPURAM CAMPUS
Unit I
UML DIAGRAMS
Dr.S.Veena,Associate Professor/CSE 1
Introduction to OOAD with OO Basics
Definition of OOP Concepts in Java
• Object-oriented Programming (OOP) is a programming paradigm
based upon objects (having both data and methods) that aims to
incorporate the advantages of modularity and reusability.
Dr.S.Veena,Associate Professor/CSE 2
Basic Terminologies of Object Oriented Systems
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:
– Identity that distinguishes it from other objects in the system.
– State that determines the characteristic properties of an object as well as
the values of the properties that the object holds.
– Behavior that represents externally visible activities performed by an
object in terms of changes in its state.
• 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.
Dr.S.Veena,Associate Professor/CSE 3
Basic Terminologies of Object Oriented Systems
Class
• A class represents a collection of objects having same characteristic properties that exhibit
common behaviour.
• 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.
• The constituents of a class are:
– A set of attributes for the objects that are to be instantiated from the class. Generally, different objects of a class have
some difference in the values of the attributes. Attributes are often referred as class data.
– A set of operations that portray the behaviour of the objects of the class. Operations are also referred as functions or
methods.
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
Dr.S.Veena,Associate Professor/CSE 4
Basic Terminologies of Object Oriented Systems
Encapsulation
• 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.
Data Hiding
• Typically, 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.
Dr.S.Veena,Associate Professor/CSE 5
Basic Terminologies of Object Oriented Systems
Message Passing
• 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.
• The features of message passing are:
– Message passing between two objects is generally unidirectional.
– Message passing enables all interactions between objects.
– Message passing essentially involves invoking class methods.
– Objects in different processes can be involved in message
passing.
Dr.S.Veena,Associate Professor/CSE 6
Basic Terminologies of Object Oriented Systems
Inheritance
•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.
Types of Inheritance
•Single Inheritance : A subclass derives from a single super-class.
•Multiple Inheritance : A subclass derives from more than one super-classes.
•Multilevel Inheritance : A subclass derives from a super-class which in turn is derived
from another class and so on.
•Hierarchical Inheritance : A class has a number of subclasses each of which may have
subsequent subclasses, continuing for a number of levels, so as to form a tree structure.
•Hybrid Inheritance : A combination of multiple and multilevel inheritance so as to form a
lattice structure.
Dr.S.Veena,Associate Professor/CSE 7
Basic Terminologies of Object Oriented Systems
Polymorphism
• Polymorphism is originally a Greek word that means the ability to take
multiple forms.
• In object-oriented paradigm, polymorphism implies using operations in
different ways, depending upon the instance they are operating upon.
• Polymorphism allows objects with different internal structures to
have a common external interface.
• Polymorphism is particularly effective while implementing inheritance.
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.
Dr.S.Veena,Associate Professor/CSE 8
Basic Terminologies of Object Oriented Systems
Generalization
• In the generalization process, the common characteristics of classes are
combined to form a class in a higher level of hierarchy, i.e., subclasses are
combined to form a generalized super-class. It represents an “is – a – kind – of”
relationship. For example, “car is a kind of land vehicle”, or “ship is a kind of water
vehicle”.
Specialization
• Specialization is the reverse process of generalization. Here, the distinguishing
features of groups of objects are used to form specialized classes from
existing classes. It can be said that the subclasses are the specialized versions of
the super-class.
Dr.S.Veena,Associate Professor/CSE 9
Basic Terminologies of Object Oriented Systems
Dr.S.Veena,Associate Professor/CSE 11
Basic Terminologies of Object Oriented Systems
Aggregation or Composition
• Aggregation or composition is a relationship among classes by which a
class can be made up of any combination of objects of other classes.
• It allows objects to be placed directly within the body of other classes.
• Aggregation is referred as a “part–of” or “has–a” relationship, with the
ability to navigate from the whole to its parts.
• An aggregate object is an object that is composed of one or more other
objects.
Example
• In the relationship, “a car has–a motor”, car is the whole object or the
aggregate, and the motor is a “part–of” the car. Aggregation may denote:
• Physical containment : Example, a computer is composed of monitor, CPU,
mouse, keyboard, and so on.
• Conceptual containment : Example, shareholder has–a share.
Dr.S.Veena,Associate Professor/CSE 12
Benefits of Object Model
The benefits of using the object model are:
• It helps in faster development of software.
• It is easy to maintain. Suppose a module develops an
error, then a programmer can fix that particular module,
while the other parts of the software are still up and
running.
• It supports relatively hassle-free upgrades.
• It enables reuse of objects, designs, and functions.
• It reduces development risks, particularly in
integration of complex systems
Dr.S.Veena,Associate Professor/CSE 13
Introduction to OOAD with OO Basics
Object-Oriented Analysis And Design
• Object-oriented analysis and design (OOAD) is a
software engineering approach that models a system as
a group of interacting objects.
• Each object represents some entity of interest in the system being
modeled, and is characterized by its class, its state (data
elements), and its behavior.
• Various models can be created to show the static structure,
dynamic behavior, and run-time deployment of these
collaborating objects.
• There are a number of different notations for representing
these models, such as the Unified Modeling Language
(UML).
Dr.S.Veena,Associate Professor/CSE 14
Definition of Analysis and Design
Dr.S.Veena,Associate Professor/CSE 15
Definition of Object-Oriented Analysis and Design
Dr.S.Veena,Associate Professor/CSE 16
What is UML?
Dr.S.Veena,Associate Professor/CSE 17
Motivations for UML
Dr.S.Veena,Associate Professor/CSE 18
Types of UML diagrams
Dr.S.Veena,Associate Professor/CSE 19
UML syntax
• Actors: a UML actor indicates an interface
(point of interaction) with the system.
– We use actors to group and name sets of system
interactions.
– Actors may be people, or other systems.
– An actor is NOT part of the system you are modeling.
– An actor is something external that your system has
to deal with.
• Boxes: It is used variously throughout UML to
indicate discrete elements, groupings and
containment.
Dr.S.Veena,Associate Professor/CSE 20
UML syntax
• Arrows: arrows indicate all manner of things, depending on
which particular type of UML diagram they’re in. Usually,
arrows indicate flow, dependency, association or
generalization.
• Cardinality: applied to arrows, cardinalities show relative
numerical relationships between elements in a model:
1 to 1, 1 to many, etc.
• Constraints: allow notation of arbitrary constraints on model
elements. Used, for example, to constrain the value of a
class attribute (a piece of data).
• Stereotypes: allow us to extend the semantics of UML
with English. A stereotype is usually a word or short
phrase that describes what a diagram element does.
Dr.S.Veena,Associate Professor/CSE 21
UML diagrams
• A single diagram is not enough to cover
all aspects of the system.
• So UML defines various kinds of
diagrams to cover most of the aspects of
a system.
• There are two broad categories of diagrams and
then are again divided into sub-categories:
– Structural Diagrams
– Behavioral Diagrams
Dr.S.Veena,Associate Professor/CSE 22
Structural Diagrams
• The structural diagrams represent the
static aspect of the system.
• These static parts are represents by
classes, interfaces, objects, components
and nodes. The four structural diagrams are:
– Class diagram
– Object diagram
– Component diagram
– Deployment diagram
Dr.S.Veena,Associate Professor/CSE 23
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.
• Active class is used in a class diagram to
represent the concurrency of the system.
Dr.S.Veena,Associate Professor/CSE 24
Class Diagram
Dr.S.Veena,Associate Professor/CSE 25
Object Diagram
• Object diagrams can be described as an
instance of class diagram.
• Object diagrams are a set of objects and
their relationships just like class diagrams
and 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 practical
perspective.
Dr.S.Veena,Associate Professor/CSE 26
Object Diagram
Dr.S.Veena,Associate Professor/CSE 27
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.
• During 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.
• Finally, component diagrams are used to visualize the
implementation.
Dr.S.Veena,Associate Professor/CSE 28
Component Diagram
Dr.S.Veena,Associate Professor/CSE 29
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 deployment view of a
system.
• This is generally used by the deployment
team.
Dr.S.Veena,Associate Professor/CSE 30
Deployment Diagram
Dr.S.Veena,Associate Professor/CSE 31
Behavioral Diagrams
• Any system can have two aspects, static and dynamic. So a model
is considered as complete when both the aspects are covered fully.
• Behavioral diagrams basically capture the dynamic
aspect of a system.
• Dynamic aspect can be further described as the
changing/moving parts of a system.
Dr.S.Veena,Associate Professor/CSE 32
Behavioral Diagrams-Use case
• Use case diagrams are a set of use
cases, actors and their relationships.
• They represent the use case view of a system.
• A use case represents a particular
functionality of a system.
• So use case diagram is used to describe the
relationships among the functionalities
and their internal/external controllers.
These controllers are known as actors.
Dr.S.Veena,Associate Professor/CSE 33
Use case Diagram
Dr.S.Veena,Associate Professor/CSE 35
Use Case Diagram
Dr.S.Veena,Associate Professor/CSE 36
Behavioral Diagrams –Sequence Diagram
Dr.S.Veena,Associate Professor/CSE 38
Behavioral Diagrams –Collaboration Diagram
Dr.S.Veena,Associate Professor/CSE 39
Collaboration Diagram
Dr.S.Veena,Associate Professor/CSE 40
Behavioral Diagram – State chart Diagram
Dr.S.Veena,Associate Professor/CSE 42
Behavioral Diagram – Activity Diagram
Dr.S.Veena,Associate Professor/CSE 43
Activity Diagram
Dr.S.Veena,Associate Professor/CSE 44
Use Case Modelling in OOAD
A use-case model is a model of how different types of
users interact with the system to solve a problem.
Dr.S.Veena,Associate Professor/CSE 45
Use Case Modelling in OOAD
Actor
•model element representing each actor. Properties include the
actors name and brief description.
Use Case
•A model element representing each use case. Properties include
the use case name and use case specification.
Associations
•Associations are used to describe the relationships between
actors and the use cases they participate in. This relationship
is commonly known as a “communicates- association”.
Dr.S.Veena,Associate Professor/CSE 46
Use Case Modelling in OOAD
Advanced model elements
The use-case model may also contain the following
advanced model elements.
Subject Or System Boundary
•A model element that represents the boundary of the
system of interest.
Use-Case Package
•A model element used to structure the use case
model to simplify analysis, communications,
navigation, and planning. If there are many use
cases or actors, you can use use-case packages to
further structure the use-case model in much the
same manner you use folders or directories to
structure the information on your hard-disk.
Dr.S.Veena,Associate Professor/CSE 47
Use Case Modelling in OOAD
Dependencies
Dr.S.Veena,Associate Professor/CSE 48
Use Case Modelling in OOAD
• The system boundary is defined by who or what uses the system
(i.e. the actors), and what specific benefits the system
offers to those actors (i.e. the use cases).
• The system boundary is drawn as a box, labeled with the name of the
system, with the actors drawn outside the boundary and the use
cases inside.
Dr.S.Veena,Associate Professor/CSE 49
Use Case Modelling in OOAD
• Actor Generalization - create an abstract actor called Purchaser that
interacts with the use cases ListProducts, OrderProducts, and
AcceptPayment. Customer and SalesAgent are known as concrete
actors because real people (or other systems) could fulfill those
roles. In addition, SalesAgent has another interaction with the use
case CalculateCommission that is not inherited
Dr.S.Veena,Associate Professor/CSE 50
Relating Use Cases Include, Extend and Generalization
• In UML, a relationship is a
connection between model
elements.
• A UML relationship is a type of model
element that adds semantics to a
model by defining the structure
and behavior between the model
elements
Dr.S.Veena,Associate Professor/CSE 51
Relating Use Cases Include, Extend and Generalization
•in
The followingdiagrams:
use-case describe the relationships that you can use
Association relationships
•In UML models, an association is a relationship
between two classifiers, such as classes or use cases,
that describes the reasons for the relationship and the
rules that governrelationships
Generalization the relationship.
•relationship
In based
UML modeling, a generalization
in which one model relationship
element (the is a
child)
is
•component, on
Generalization another model
relationships element
areall
used (the parent).
in attributes,
class,
indicate that
operations, deployment,
the
and child and
receives
relationships use-case
that of
arethe diagrams
defined in theto
parent.
Include relationships
•In UML modeling, an include relationship is a
relationship in which one use case (the base use
case) includes the functionality of another use case
(the inclusion use case). The include relationship
supportsrelationships
Extend the reuse of functionality in a use-case model.
•specify
In UML that
behavior modeling,
of one
anotheryouuse
use cancase
case use an extend
(extension)
(base). relationship
extends
This type ofthe to
relationship reveals
that are typically details
hidden inabout
a use acase.
system or application
Dr.S.Veena,Associate Professor/CSE 53
Relating Use Cases Include, Extend and Generalization
Dr.S.Veena,Associate Professor/CSE 54
Relating Use Cases Include, Extend and Generalization
Dr.S.Veena,Associate Professor/CSE 55
Relating Use Cases Include, Extend and Generalization
Generalization of an Actor
•Generalization of an actor means that one actor can inherit the
role of the other actor. The descendant inherits all the use
cases of the ancestor. The descendant has one or more use
cases that are specific to that role.
Dr.S.Veena,Associate Professor/CSE 56
Relating Use Cases Include, Extend and Generalization
Dr.S.Veena,Associate Professor/CSE 57
Relating Use Cases Include, Extend and Generalization
Dr.S.Veena,Associate Professor/CSE 58
Relating Use Cases Include, Extend and Generalization
Dr.S.Veena,Associate Professor/CSE 59
Relating Use Cases Include, Extend and Generalization
Dr.S.Veena,Associate Professor/CSE 60
Relating Use Cases Include, Extend and Generalization
Dr.S.Veena,Associate Professor/CSE 61
Relating Use Cases Include, Extend and Generalization
Dr.S.Veena,Associate Professor/CSE 62
Relating Use Cases Include, Extend and Generalization
Dr.S.Veena,Associate Professor/CSE 63
When to use Use-Cases in OOAD
Purpose of Use Case 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 through actors.
Dr.S.Veena,Associate Professor/CSE 64