OOSD BTCS505B Notes Unit 2
OOSD BTCS505B Notes Unit 2
KALINGA UNIVERSITY
FACULTY OF COMPUTER SCIENCE & IT
Unit- II
Modeling
Modeling means creating a diagram for a system that includes identifying the elements that are
important to your particular module. The structural modeling gives a structural view of a system that
highlights the structure of the objects including their classifiers, relationships, attributes and
operations. These elements form the vocabulary of the system you are modeling. For example, if you
are going to buy a car, things like wheels, frame size, color, lights, and engine are some things that
will be worthful to you in understanding about the car; these things are properties of the car. In UML,
all of these things are modelled as classes. Cars have external and internal structure, only important
properties of car are visible and the rest are hidden. This feature is called abstraction. A class is an
abstraction of the things that are a part of your vocabulary. For creating a structural model, you have to
collect key data contained in the problem domains.
The core elements of the structural modeling are class, interface, component, node and constraints and
they are described with their notations in Table 2.1.
Classes
A class describes a group of objects which have common attributes or properties, operations or
behavior, relationships and semantics. Classes are an essential structure of any object-oriented system.
When you develop any system, you need classes to collect the system's vocabulary. These classes may
relate to the problem domain as well as implementation. Classes can be used to represent anything
from hardware, software to purely conceptual things. A class describes only important attributes to an
application and ignores the rest ; it is known as an abstraction, an important feature of object-oriented
concepts.
A class is graphically designed as a rectangle with three sections that comprises its name, attributes
and operations as shown in the figure-2.2. For example, Car class contains attributes (maker name,
wheel size, gears, frame size and color) and operations (repair, move) as shown in figure-2.3.
Each class must have a unique name. A class name is a textual string that comprises any
numbers of letters, numeric and punctuation marks. For example, Car, Book, Teacher, Account
or Person etc.
A class may or may not have attributes. An attribute is defined by a name that contains a
series of values. For example: Person class have attributes like name, age, address. In the
similar way, Car class may have attributes like frame size, wheel size, gears, color and make as
shown in figure-2.3. You can also mention attributes ‘types’ such as String or integer etc. , as
shown in figure-2.4.
A class may or may not have operations. An operation describes the behavior of the class. An
operation has a name like a class name. Usually, the operation name is written as a short text
string that represents some behaviour of its enclosing class. For example, Car class may have
operations like move, repair as shown in figure-2.4. You can identify an operation by declaring
its signature. Graphically, operations are given in a section just below the class attributes.
You can also define the visibility of class members (attributes and operations) by using plus
sign (+) for public, negative sign (-) for private, hash sign (#) for protected and tilde (~) for the
package. You can see in figure-2.4 where all attributes and operations are mentioned as public.
Relationships
Relationships define how classes communicate with each other. There are three basic types of
relationships in UML- Dependencies, Generalization and Associations for connecting or
communicating classes to each other. Graphically, a relationship is shown as a path with different
types of lines used to differentiate the categories of relationships between classes.
Dependency describes the relationships among classes in which one class is dependent on another
class. It means that if you make changes in one class, it will affect the other class. For example, class
Vehicle uses the properties and operations of another class (say Bodyshop) but not necessarily the
reverse. You can show dependency as a dashed directed line, directed to the class being dependent
upon the class. As you can see in figure-2.5, vehicle class is dependent on ‘Bodyshop’ class.
Generalization is a “a-kind-of” relationship. It creates relationships between superclass(base class)
and subclass, enabling inheritance of attributes and operations. It defines a base( parent) class with
some properties functions. A new class will be derived from this base class and it is called child or sub
4
class of the base class. The child class can use the properties and operations of the superclass. As you
can see in figure-2.5, vehicle class is super class or base or parent class and Car, Bus are child class or
sub class. The generalization is depicted as a solid line with a hollow arrow pointing to the superclass.
For example, IGNOU University have many schools. In figure-2.6, there are two classes Schools and
University. Both the classes are related to each other, and their relationship is defined by association.
This association has a name as Works-for, and role names are employee and employer. The employee
of schools worked for employer i.e. University. Under the university, there are many schools, so
5
Common Mechanisms
During designing your application, you might need to describe information through representations.
This section explains to you some important terms or notations that might be useful in designing UML
diagrams. These notations like notes, tagged values, stereotypes, constraints are demonstrated by
using the following figure-2.7:
Notes are used to define comments, explanations for documentation purposes only. It cannot have any
effect on the semantics of the model. A note may simply comprise normal text or graphical symbols.
Graphically, a note is depicted as a rectangle box with a dog-eared corner along with the comment.
You can see the note as an embedded URL notation in figure-2.7.
Tagged value is used to create extension or new information of properties of UML element.
Graphically, you can draw a tagged value as a string enclosed in {brackets}.
A stereotype is used to create new building blocks. Using stereotypes, we can use the basic elements
but with special properties, semantics and notation. Graphically, you can represent stereotypes as text
name inside guillemets(<< >>) and place them above the name of another element. You can see
stereotype notation as a <<lastdate>> above the class course element in figure-2.7.
Constraint is defined as a condition for a UML element that will be cheeked at the run-time of
applications. Graphically, you can draw as a string enclosed in {brackets} and can be put in a note.
You can see constraint as a condition notation for course class in figure-2.7.
When you use these notations in your UML diagram, keep in mind such points as always use short
notes, use notes only when the facts cannot be conversed using UML, don not use too many
graphical stereotypes, tagged values and constraints; use only common and simple supplements.
6
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.
a. The attributes are written along with its visibility factors, which are public (+), private (-),
protected (#), and package (~).
b. The accessibility of an attribute class is illustrated by the visibility factors.
c. A meaningful name should be assigned to the attribute, which will explain its usage
inside the class.
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.
Relationships
In UML, relationships are of three types:
o Dependency: A dependency is a semantic relationship between two or more classes where a
change in one class cause changes in another class. It forms a weaker relationship.
In the following example, Student_Name is dependent on the Student_Id.
v
o Association: It describes a static or physical connection between two or more objects. It
depicts how many objects are there in the relationship.
For example, a department is associated with the college.
The company encompasses a number of employees, and even if one employee resigns, the
company still exists.
A contact book consists of multiple contacts, and if you delete the contact book, all the contacts
will be lost.
Both the object and class diagram are similar to some extent; the only difference is that the class
diagram provides an abstract view of a system. It helps in visualizing a particular functionality of a
system.
The object diagram is actually similar to the concrete (actual) system behavior. The main purpose is to
depict a static view of a system.
2. Dynamic changes are not included Dynamic changes are captured in the object
in the class diagram. diagram.
3. The data values and attributes of an It incorporates data values and attributes of an
instance are not involved here. entity.
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.
12
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.
Sequence Diagram
The sequence diagram represents the flow of messages in the system and is also termed as an event
diagram. It helps in envisioning several dynamic scenarios. It portrays the communication between
any two lifelines as a time-ordered sequence of events, such that these lifelines took part at the run
time. In UML, the lifeline is represented by a vertical bar, whereas the message flow is represented by
a vertical dotted line that extends across the bottom of the page. It incorporates the iterations as well as
branching.
Lifeline
An individual participant in the sequence diagram is represented by a lifeline. It is positioned at the top
of the diagram.
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.
14
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
The messages depict the interaction between the objects and are represented by arrows. They are in the
sequential order on the lifeline. The core of the sequence diagram is formed by messages and lifelines.
o
15
o 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.
o
16
Note
A note is the capability of attaching several remarks to the element. It basically carries useful
information for the modelers.
17
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
Following are the types of fragments enlisted below;
alt Alternative multiple fragments: The only fragment for which the condition is true, will
execute.
opt Optional: If the supplied condition is true, only then the fragments will execute. It is
similar to alt with only one trace.
loop Loop: Fragments are run multiple times, and the basis of interaction is shown by the
guard.
region Critical region: Only one thread can execute a fragment at once.
The sequence diagram represents the UML, The collaboration diagram also comes under the
which is used to visualize the sequence of calls UML representation which is used to visualize
in a system that is used to perform a specific the organization of the objects and their
functionality. interaction.
The sequence diagram are used to represent the The collaboration diagram are used to represent
sequence of messages that are flowing from one the structural organization of the system and the
object to another. messages that are sent and received.
The sequence diagram is used when time The collaboration diagram is used when object
sequence is main focus. organization is main focus.
Interaction Diagrams
Interaction diagrams are a subclass of behavioral diagrams that give emphasis to object interactions
and also depicts the flow between various use case elements of a system. In simple words, it shows
how objects interact with each other and how the data flows within them. It consists of
communication, interaction overview, sequence, and timing diagrams.
o Sequence Diagram: It shows the interactions between the objects in terms of messages
exchanged over time. It delineates in what order and how the object functions are in a system.
o Communication Diagram: It shows the interchange of sequence messages between the
objects. It focuses on objects and their relations. It describes the static and dynamic behavior of
a system.
o Timing Diagram: It is a special kind of sequence diagram used to depict the object's behavior
over a specific period of time. It governs the change in state and object behavior by showing
the time and duration constraints.
o Interaction Overview diagram: It is a mixture of activity and sequence diagram that depicts a
sequence of actions to simplify the complex interactions into simple interactions.
Behavioral Model is specially designed to make us understand behavior and factors that influence
behavior of a System. Behavior of a system is explained and represented with the help of a diagram.
This diagram is known as State Transition Diagram. It is a collection of states and events. It usually
describes overall states that a system can have and events which are responsible for a change in state
of a system.
20
So, on some occurrence of a particular event, an action is taken and what action needs to be taken is
represented by State Transition Diagram.
Example :
Consider an Elevator. This elevator is for n number of floors and has n number of buttons one for
each floor.
Elevator’s working can be explained as follows :
1. Elevator buttons are type of set of buttons which is there on elevator. For reaching a particular
floor you want to visit, “elevator buttons” for that particular floor is pressed. Pressing, will cause
illumination and elevator will start moving towards that particular floor for which you pressed
“elevator buttons”. As soon as elevator reaches that particular floor,
illumination gets canceled.
2. Floor buttons are another type of set of buttons on elevator. If a person is on a particular floor
and he wants to go on another floor, then elevator button for that floor is pressed. Then, process
will be same as given above. Pressing, will cause illumination and elevator to start moving, and
when it reaches on desired floor, illumination gets canceled.
3. When there is no request for elevator, it remains closed on current floor.
State Transition Diagram for an elevator system is shown below –
Advantages :
Behavior and working of a system can easily be understood without any effort.
Results are more accurate by using this model.
This model requires less cost for development as cost of resources can be minimal.
It focuses on behavior of a system rather than theories.
Disadvantages :
This model does not have any theory, so trainee is not able to fully understand basic principle
and major concept of modeling.
This modeling cannot be fully automated.
Sometimes, it’s not easy to understand overall result.
Does not achieve maximum productivity due to some technical issues or any errors.
21
Activity Diagram
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.
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.
Timing Diagram
In UML, the timing diagrams are a part of Interaction diagrams that do not incorporate similar
notations as that of sequence and collaboration diagram. It consists of a graph or waveform that
depicts the state of a lifeline at a specific point of time. It illustrates how conditions are altered both
inside and between lifelines alongside linear time axis.
23
The timing diagram describes how an object underwent a change from one form to another. A
waveform portrays the flow among the software programs at several instances of time.
Interaction Diagram
the interaction diagram portrays the interactions between distinct entities present in the model. It
amalgamates both the activity and sequence diagrams. The communication is nothing but units of the
behavior of a classifier that provides context for interactions.
A set of messages that are interchanged between the entities to achieve certain specified tasks in the
system is termed as interaction. It may incorporate any feature of the classifier of which it has access.
In the interaction diagram, the critical component is the messages and the lifeline.
In UML, the interaction overview diagram initiates the interaction between the objects utilizing
message passing. While drawing an interaction diagram, the entire focus is to represent the
relationship among different objects which are available within the system boundary and the message
exchanged by them to communicate with each other.
The message exchanged among objects is either to pass some information or to request some
information. And based on the information, the interaction diagram is categorized into the sequence
diagram, collaboration diagram, and timing diagram.
Package Diagram
Package diagram, a kind of structural diagram, shows the arrangement and organization of model
elements in middle to large scale project. Package diagram can show both structure and
dependencies between sub-systems or modules, showing different views of a system, for example, as
multi-layered (aka multi-tiered) application - multi-layered application model.
Architectural Modeling
Architectural model represents the overall framework of the system. It contains both structural and
behavioral elements of the system. Architectural model can be defined as the blueprint of the entire
system. Package diagram comes under architectural modeling.
Components
A component is a physical and replaceable part of a system that conforms to and provide the
realization of a set of interfaces
It is used to model physical things like executable's, libraries, tables, files and
documents Graphically represented as a rectangle with tabs
Names
Components and Classes
Components and Interfaces
Binary Replace ability
Kinds of Components
Common Modeling Techniques
Names:
Name of every component should be unique, in order to distinguish it from other components
It has simple and path names
➤A component is
Physical, it lives in the world of bits not in concepts
Replaceable, it is possible to replace a component with another that conforms to the same interfaces
Part of a system, it rarely stands alone
➤A component conforms to and provides the realization of a set of interfaces
Kinds of Components:
Deployment Components: These components form an executable system like Dynamic Libraries
(DLLs) and Executables (EXEs)
Work Product Components: These components contains source code files and data files from which
deployment components are created
Execution Components: These components are created as a consequence of an executing system, like
COM+ object which is instantiated from a DLL
Component Diagram
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.
Deployment Diagram
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.
Modelling
A model is an abstraction of something for the purpose of understanding it before building it.
Because a model omits nonessential details, it is easier to manipulate than the original entity.
Abstraction is a fundamental human capability that permits us to deal with complexity.
Engineers, artists, and craftsmen have built models for thousands of years to try out designs
before executing them. Development of hardware and software systems is no exception. To
build complex systems, the developer must abstract different views of the system, build models
using precise notations, verify that the models satisfy the requirements of the system, and
gradually add detail to transform the models into an implementation.
Designers build many kinds of models for various purposes before constructing things.
Examples include architectural models to show customers, airplane scale models for wind-
tunnel tests, pencil sketches for composition of oil paintings, blueprints of machine parts,
storyboards of advertisements, and outlines of books. Models serve several purposes.
26
a. Testing a physical entity before building it: The medieval masons did not know modern
physics, but they built scale models of the Gothic cathedrals to test the forces on the
structure. Engineers test scale models of airplanes, cars, and boats in wind tunnels and water
tanks to improve their dynamics. Recent advances in computation permit the simulation of
many physical structures without the need to build physical models. Not only is simulation
cheaper, but it provides information that is too fleeting or inaccessible to be measured from a
physical model. Both physical models and computer models are usually cheaper than
building a complete system and enable early correction of flaws.
b. Communication with customers. Architects and product designers build models to show
their customers. Mock-ups are demonstration products that imitate some or all of the
external behavior of a system.
Modelling
A model is an abstraction of something for the purpose of understanding it before building it.
Because a model omits nonessential details, it is easier to manipulate than the original entity.
Abstraction is a fundamental human capability that permits us to deal with complexity.
Engineers, artists, and craftsmen have built models for thousands of years to try out designs
before executing them. Development of hardware and software systems is no exception. To
build complex systems, the developer must abstract different views of the system, build models
using precise notations, verify that the models satisfy the requirements of the system, and
gradually add detail to transform the models into an implementation.
Designers build many kinds of models for various purposes before constructing things.
Examples include architectural models to show customers, airplane scale models for wind-
tunnel tests, pencil sketches for composition of oil paintings, blueprints of machine parts,
storyboards of advertisements, and outlines of books. Models serve several purposes.
a. Testing a physical entity before building it: The medieval masons did not know modern
physics, but they built scale models of the Gothic cathedrals to test the forces on the
structure. Engineers test scale models of airplanes, cars, and boats in wind tunnels and water
tanks to improve their dynamics. Recent advances in computation permit the simulation of
many physical structures without the need to build physical models. Not only is simulation
cheaper, but it provides information that is too fleeting or inaccessible to be measured from a
physical model. Both physical models and computer models are usually cheaper than
building a complete system and enable early correction of flaws.
b. Communication with customers. Architects and product designers build models to show
their customers. Mock-ups are demonstration products that imitate some or all of the
external behavior of a system.