OOAD Chapter 5
OOAD Chapter 5
OOAD Chapter 5
In the system analysis or object-oriented analysis phase of software development, the system
requirements are determined, the classes are identified and the relationships among classes are
identified.
The three analysis techniques that are used in conjunction with each other for object-oriented
analysis are object modelling, dynamic modelling, and functional modelling.
Object Modelling
Object modelling develops the static structure of the software system in terms of objects. It
identifies the objects, the classes into which the objects can be grouped into and the
relationships between the objects. It also identifies the main attributes and operations that
characterize each class.
The process of object modelling can be visualized in the following steps −
Dynamic Modelling
After the static behavior of the system is analyzed, its behavior with respect to time and external
changes needs to be examined. This is the purpose of dynamic modelling.
Dynamic Modelling can be defined as “a way of describing how an individual object responds
to events, either internal events triggered by other objects, or external events triggered by the
outside world”.
The process of dynamic modelling can be visualized in the following steps −
Functional Modelling
Functional Modelling is the final component of object-oriented analysis. The functional model
shows the processes that are performed within an object and how the data changes as it moves
between methods. It specifies the meaning of the operations of object modelling and the actions
of dynamic modelling. The functional model corresponds to the data flow diagram of traditional
structured analysis.
The process of functional modelling can be visualized in the following steps −
Feasibility Study
Requirement Analysis and Specification
System Design
Implementation
Post-implementation Review
Now, we will look at the relative advantages and disadvantages of structured analysis approach
and object-oriented analysis approach.
Advantages/Disadvantages of Object Oriented Analysis
Advantages Disadvantages
Focuses on data rather than the procedures as in Functionality is restricted within objects. This may
Structured Analysis. pose a problem for systems which are intrinsically
procedural or computational in nature.
The principles of encapsulation and data hiding It cannot identify which objects would generate an
help the developer to develop systems that cannot optimal system design.
be tampered by other parts of the system.
The principles of encapsulation and data hiding The object-oriented models do not easily show the
help the developer to develop systems that cannot communications between the objects in the system.
be tampered by other parts of the system.
It allows effective management of software All the interfaces between the objects cannot be
complexity by the virtue of modularity. represented in a single diagram.
It is based upon functionality. The overall purpose is The initial cost of constructing the system is
identified and then functional decomposition is done for high, since the whole system needs to be
developing the software. The emphasis not only gives a designed at once leaving very little option
better understanding of the system but also generates more to add functionality later.
complete systems.
The specifications in it are written in simple English It does not support reusability of code. So,
language, and hence can be more easily analyzed by non- the time and cost of development is
technical personnel. inherently high.
OOAD - Dynamic Modeling
The dynamic model represents the time–dependent aspects of a system. It is concerned with the
temporal changes in the states of the objects in a system. The main concepts are −
State, which is the situation at a particular condition during the lifetime of an object.
Transition, a change in the state
Event, an occurrence that triggers transitions
Action, an uninterrupted and atomic computation that occurs due to some event, and
Concurrency of transitions.
A state machine models the behavior of an object as it passes through a number of states in its
lifetime due to some events as well as the actions occurring due to the events. A state machine
is graphically represented through a state transition diagram.
State
The state is an abstraction given by the values of the attributes that the object has at a particular
time period. It is a situation occurring for a finite time period in the lifetime of an object, in
which it fulfils certain conditions, performs certain activities, or waits for certain events to
occur. In state transition diagrams, a state is represented by rounded rectangles.
Parts of a state
Name − A string differentiates one state from another. A state may not have any name.
Entry/Exit Actions − It denotes the activities performed on entering and on exiting the
state.
Internal Transitions − The changes within a state that do not cause a change in the
state.
Sub–states − States within states.
Example
Suppose a person is taking a taxi from place X to place Y. The states of the person may be:
Waiting (waiting for taxi), Riding (he has got a taxi and is travelling in it), and Reached (he has
reached the destination). The following figure depicts the state transition.
Events
Events are some occurrences that can trigger state transition of an object or a group of objects.
Events have a location in time and space but do not have a time period associated with it.
Events are generally associated with some actions.
Examples of events are mouse click, key press, an interrupt, stack overflow, etc.
Events that trigger transitions are written alongside the arc of transition in state diagrams.
Example
Considering the example shown in the above figure, the transition from Waiting state to Riding
state takes place when the person gets a taxi. Likewise, the final state is reached, when he
reaches the destination. These two occurrences can be termed as events Get_Taxi and
Reach_Destination. The following figure shows the events in a state machine.
External and Internal Events
External events are those events that pass from a user of the system to the objects within the
system. For example, mouse click or key−press by the user are external events.
Internal events are those that pass from one object to another object within a system. For
example, stack overflow, a divide error, etc.
Deferred Events
Deferred events are those which are not immediately handled by the object in the current state
but are lined up in a queue so that they can be handled by the object in some other state at a later
time.
Event Classes
Event class indicates a group of events with common structure and behavior. As with classes of
objects, event classes may also be organized in a hierarchical structure. Event classes may have
attributes associated with them, time being an implicit attribute. For example, we can consider
the events of departure of a flight of an airline, which we can group into the following class −
Flight_Departs (Flight_No, From_City, To_City, Route)
Actions
Activity
Activity is an operation upon the states of an object that requires some time period. They are the
ongoing executions within a system that can be interrupted. Activities are shown in activity
diagrams that portray the flow from one activity to another.
Action
An action is an atomic operation that executes as a result of certain events. By atomic, it is
meant that actions are un-interruptible, i.e., if an action starts executing, it runs into completion
without being interrupted by any event. An action may operate upon an object on which an
event has been triggered or on other objects that are visible to this object. A set of actions
comprise an activity.
Entry and Exit Actions
Entry action is the action that is executed on entering a state, irrespective of the transition that
led into it.
Likewise, the action that is executed while leaving a state, irrespective of the transition that led
out of it, is called an exit action.
Scenario
Scenario is a description of a specified sequence of actions. It depicts the behavior of objects
undergoing a specific action series. The primary scenarios depict the essential sequences and the
secondary scenarios depict the alternative sequences.
There are two primary diagrams that are used for dynamic modelling −
Interaction Diagrams
Interaction diagrams describe the dynamic behavior among different objects. It comprises of a
set of objects, their relationships, and the message that the objects send and receive. Thus, an
interaction models the behavior of a group of interrelated objects. The two types of interaction
diagrams are −
Sequence Diagram − It represents the temporal ordering of messages in a tabular
manner.
Collaboration Diagram − It represents the structural organization of objects that send
and receive messages through vertices and arcs.
State Transition Diagram
State transition diagrams or state machines describe the dynamic behavior of a single object. It
illustrates the sequences of states that an object goes through in its lifetime, the transitions of the
states, the events and conditions causing the transition and the responses due to the events.
Concurrency of Events
Concurrent Sub-states
In concurrent sub-states, the sub-states execute in parallel, or in other words, each state has
concurrently executing state machines within it. Each of the state machines has its own initial
and final states. If one concurrent sub-state reaches its final state before the other, control waits
at its final state. When all the nested state machines reach their final states, the sub-states join
back to a single flow.
The following figure shows the concept of concurrent sub-states.
OOAD - Functional Modeling
Functional Modelling gives the process perspective of the object-oriented analysis model and an
overview of what the system is supposed to do. It defines the function of the internal processes
in the system with the aid of Data Flow Diagrams (DFDs). It depicts the functional derivation of
the data values without indicating how they are derived when they are computed, or why they
need to be computed.
Processes,
Data Flows,
Actors, and
Data Stores.
The other parts of a DFD are −
Constraints, and
Control Flows.
Features of a DFD
Processes
Processes are the computational activities that transform data values. A whole system can be
visualized as a high-level process. A process may be further divided into smaller components.
The lowest-level process may be a simple function.
Representation in DFD − A process is represented as an ellipse with its name written inside it
and contains a fixed number of input and output data values.
Example − The following figure shows a process Compute_HCF_LCM that accepts two
integers as inputs and outputs their HCF (highest common factor) and LCM (least common
multiple).
Data Flows
Data flow represents the flow of data between two processes. It could be between an actor and a
process, or between a data store and a process. A data flow denotes the value of a data item at
some point of the computation. This value is not changed by the data flow.
Representation in DFD − A data flow is represented by a directed arc or an arrow, labelled
with the name of the data item that it carries.
In the above figure, Integer_a and Integer_b represent the input data flows to the process, while
L.C.M. and H.C.F. are the output data flows.
A data flow may be forked in the following cases −
The output value is sent to several places as shown in the following figure. Here, the
output arrows are unlabelled as they denote the same value.
The data flow contains an aggregate value, and each of the components is sent to
different places as shown in the following figure. Here, each of the forked components is
labelled.
Actors
Actors are the active objects that interact with the system by either producing data and inputting
them to the system, or consuming data produced by the system. In other words, actors serve as
the sources and the sinks of data.
Representation in DFD − An actor is represented by a rectangle. Actors are connected to the
inputs and outputs and lie on the boundary of the DFD.
Example − The following figure shows the actors, namely, Customer and Sales_Clerk in a
counter sales system.
Data Stores
Data stores are the passive objects that act as a repository of data. Unlike actors, they cannot
perform any operations. They are used to store data and retrieve the stored data. They represent
a data structure, a disk file, or a table in a database.
Representation in DFD − A data store is represented by two parallel lines containing the name
of the data store. Each data store is connected to at least one process. Input arrows contain
information to modify the contents of the data store, while output arrows contain information
retrieved from the data store. When a part of the information is to be retrieved, the output arrow
is labelled. An unlabelled arrow denotes full data retrieval. A two-way arrow implies both
retrieval and update.
Example − The following figure shows a data store, Sales_Record, that stores the details of all
sales. Input to the data store comprises of details of sales such as item, billing amount, date, etc.
To find the average sales, the process retrieves the sales records and computes the average.
Constraints
Constraints specify the conditions or restrictions that need to be satisfied over time. They allow
adding new rules or modifying existing ones. Constraints can appear in all the three models of
object-oriented analysis.
In Object Modelling, the constraints define the relationship between objects. They may
also define the relationship between the different values that an object may take at
different times.
In Dynamic Modelling, the constraints define the relationship between the states and
events of different objects.
In Functional Modelling, the constraints define the restrictions on the transformations
and computations.
Representation − A constraint is rendered as a string within braces.
Example − The following figure shows a portion of DFD for computing the salary of
employees of a company that has decided to give incentives to all employees of the sales
department and increment the salary of all employees of the HR department. It can be seen that
the constraint {Dept:Sales} causes incentive to be calculated only if the department is sales and
the constraint {Dept:HR} causes increment to be computed only if the department is HR.
Control Flows
A process may be associated with a certain Boolean value and is evaluated only if the value is
true, though it is not a direct input to the process. These Boolean values are called the control
flows.
Representation in DFD − Control flows are represented by a dotted arc from the process
producing the Boolean value to the process controlled by them.
Example − The following figure represents a DFD for arithmetic division. The Divisor is tested
for non-zero. If it is not zero, the control flow OK has a value True and subsequently the Divide
process computes the Quotient and the Remainder.
Developing the DFD Model of a System
In order to develop the DFD model of a system, a hierarchy of DFDs are constructed. The top-
level DFD comprises of a single process and the actors interacting with it.
At each successive lower level, further details are gradually included. A process is decomposed
into sub-processes, the data flows among the sub-processes are identified, the control flows are
determined, and the data stores are defined. While decomposing a process, the data flow into or
out of the process should match the data flow at the next level of DFD.
Example − Let us consider a software system, Wholesaler Software, that automates the
transactions of a wholesale shop. The shop sells in bulks and has a clientele comprising of
merchants and retail shop owners. Each customer is asked to register with his/her particulars
and is given a unique customer code, C_Code. Once a sale is done, the shop registers its details
and sends the goods for dispatch. Each year, the shop distributes Christmas gifts to its
customers, which comprise of a silver coin or a gold coin depending upon the total sales and the
decision of the proprietor.
The functional model for the Wholesale Software is given below. The figure below shows the
top-level DFD. It shows the software as a single process and the actors that interact with it.
The actors in the system are −
Customers
Salesperson
Proprietor
In the next level DFD, as shown in the following figure, the major processes of the system are
identified, the data stores are defined and the interaction of the processes with the actors, and
the data stores are established.
In the system, three processes can be identified, which are −
Register Customers
Process Sales
Ascertain Gifts
The data stores that will be required are −
Customer Details
Sales Details
Gift Details
The following figure shows the details of the process Register Customer. There are three
processes in it, Verify Details, Generate C_Code, and Update Customer Details. When the
details of the customer are entered, they are verified. If the data is correct, C_Code is generated
and the data store Customer Details is updated.
The following figure shows the expansion of the process Ascertain Gifts. It has two processes in
it, Find Total Sales and Decide Type of Gift Coin. The Find Total Sales process computes the
yearly total sales corresponding to each customer and records the data. Taking this record and
the decision of the proprietor as inputs, the gift coins are allotted through Decide Type of Gift
Coin process.
Advantages Disadvantages
DFDs depict the boundaries of a system and hence are DFDs take a long time to create, which may not be
helpful in portraying the relationship between the feasible for practical purposes.
external objects and the processes within the system.
They help the users to have a knowledge about the DFDs do not provide any information about the
system. time-dependent behavior, i.e., they do not specify
when the transformations are done.
The graphical representation serves as a blueprint for They do not throw any light on the frequency of
the programmers to develop a system. computations or the reasons for computations.
DFDs provide detailed information about the system The preparation of DFDs is a complex process that
processes. needs considerable expertise. Also, it is difficult
for a non-technical person to understand.
They are used as a part of the system documentation. The method of preparation is subjective and leaves
ample scope to be imprecise.
The Object Model, the Dynamic Model, and the Functional Model are complementary to each
other for a complete Object-Oriented Analysis.
Object modelling develops the static structure of the software system in terms of objects.
Thus it shows the “doers” of a system.
Dynamic Modelling develops the temporal behavior of the objects in response to
external events. It shows the sequences of operations performed on the objects.
Functional model gives an overview of what the system should do.
Brief History
System − A set of elements organized to achieve certain objectives form a system. Systems are
often divided into subsystems and described by a set of models.
Model − Model is a simplified, complete, and consistent abstraction of a system, created for
better understanding of the system.
View − A view is a projection of a system’s model from a specific perspective.
Things
Relationships
Diagrams
Things
There are four kinds of things in UML, namely −
Structural Things − These are the nouns of the UML models representing the static
elements that may be either physical or conceptual. The structural things are class,
interface, collaboration, use case, active class, components, and nodes.
Behavioral Things − These are the verbs of the UML models representing the dynamic
behavior over time and space. The two types of behavioral things are interaction and
state machine.
Grouping Things − They comprise the organizational parts of the UML models. There
is only one kind of grouping thing, i.e., package.
Annotational Things − These are the explanations in the UML models representing the
comments applied to describe elements.
Relationships
Relationships are the connection between things. The four types of relationships that can be
represented in UML are −
Dependency − This is a semantic relationship between two things such that a change in
one thing brings a change in the other. The former is the independent thing, while the
latter is the dependent thing.
Association − This is a structural relationship that represents a group of links having
common structure and common behavior.
Generalization − This represents a generalization/specialization relationship in which
subclasses inherit structure and behavior from super-classes.
Realization − This is a semantic relationship between two or more classifiers such that
one classifier lays down a contract that the other classifiers ensure to abide by.
Diagrams
A diagram is a graphical representation of a system. It comprises of a group of elements
generally in the form of a graph. UML includes nine diagrams in all, namely −
Class Diagram
Object Diagram
Use Case Diagram
Sequence Diagram
Collaboration Diagram
State Chart Diagram
Activity Diagram
Component Diagram
Deployment Diagram
Rules
UML has a number of rules so that the models are semantically self-consistent and related to
other models in the system harmoniously. UML has semantic rules for the following −
Names
Scope
Visibility
Integrity
Execution
Common Mechanisms
UML has four common mechanisms −
Specifications
Adornments
Common Divisions
Extensibility Mechanisms
Specifications
In UML, behind each graphical notation, there is a textual statement denoting the syntax and
semantics. These are the specifications. The specifications provide a semantic backplane that
contains all the parts of a system and the relationship among the different paths.
Adornments
Each element in UML has a unique graphical notation. Besides, there are notations to represent
the important aspects of an element like name, scope, visibility, etc.
Common Divisions
Object-oriented systems can be divided in many ways. The two common ways of division are −
Division of classes and objects − A class is an abstraction of a group of similar objects.
An object is the concrete instance that has actual existence in the system.
Division of Interface and Implementation − An interface defines the rules for
interaction. Implementation is the concrete realization of the rules defined in the
interface.
Extensibility Mechanisms
UML is an open-ended language. It is possible to extend the capabilities of UML in a controlled
manner to suit the requirements of a system. The extensibility mechanisms are −
Stereotypes − It extends the vocabulary of the UML, through which new building blocks
can be created out of existing ones.
Tagged Values − It extends the properties of UML building blocks.
Constraints − It extends the semantics of UML building blocks.
OOAD - UML Basic Notations
UML defines specific notations for each of the building blocks.
Class
Object
Example − Let us consider an object of the class Circle named c1. We assume that the center of
c1 is at (2, 3) and the radius of c1 is 5. The following figure depicts the object.
Component
A component is a physical and replaceable part of the system that conforms to and provides the
realization of a set of interfaces. It represents the physical packaging of elements like classes
and interfaces.
Notation − In UML diagrams, a component is represented by a rectangle with tabs as shown in
the figure below.
Interface
Interface is a collection of methods of a class or component. It specifies the set of services that
may be provided by the class or component.
Notation − Generally, an interface is drawn as a circle together with its name. An interface is
almost always attached to the class or component that realizes it. The following figure gives the
notation of an interface.
Package
A package is an organized group of elements. A package may contain structural things like
classes, components, and other packages in it.
Notation − Graphically, a package is represented by a tabbed folder. A package is generally
drawn with only its name. However it may have additional details about the contents of the
package. See the following figures.
Relationship
Usually, elements in a relationship play specific roles in the relationship. A role name signifies
the behavior of an element participating in a certain context.
Example − The following figures show examples of different relationships between classes.
The first figure shows an association between two classes, Department and Employee, wherein
a department may have a number of employees working in it. Worker is the role name. The ‘1’
alongside Department and ‘*’ alongside Employee depict that the cardinality ratio is one–to–
many. The second figure portrays the aggregation relationship, a University is the “whole–of”
many Departments.