Chapter_3
Chapter_3
1
Chapter
Outline
OO concepts from structured point of
view
Abstraction,
Encapsulation and information hiding
inheritance
Association
Aggregation
Collaboration
Persistence
Coupling
Cohesion
polymorphism
Interfaces
components
Patterns
Object-Oriented
Analysis
Object–Oriented Analysis (OOA) is the procedure of identifying software
engineering requirements and developing software specifications in terms of a
software system’s object model, which encompasses of interacting objects.
The main difference between object-oriented analysis and other forms of analysis is
that in object-oriented approach, requirements are organized around objects, which
integrate both data and functions.
They are modelled after real-world objects that the system interacts with.
In traditional analysis methodologies, the two aspects functions and data - are
considered separately.
Grady Booch has defined OOA as, “Object-oriented analysis is a method of
analysis that examines requirements from the perspective of the classes and
objects found in the vocabulary of the problem domain”.
Cntd…
The primary tasks in object-oriented analysis (OOA) are:
Identifying objects
Organizing the objects by creating object model diagram
Defining the internals of the objects, or object attributes
Defining the behavior of the objects, i.e., object actions
Describing how the objects interact
The common models used in OOA are use cases and object models.
Object-Oriented
Design
Object–Oriented Design (OOD) involves implementation of the conceptual
model produced during object-oriented analysis.
In OOD, concepts in the analysis model, which are Technology independent,
are
mapped onto implementing classes, constraints are identified and interfaces
are designed, resulting in a model for the solution domain, i.e., a detailed
description of how the system is to be built on concrete technologies.
The implementation details generally include:
Restructuring the class data (if necessary),
Implementation of methods, i.e., internal data structures and algorithms,
Implementation of control, and
Implementation of associations.
Cntd…
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,
one such model is Unified Modeling Language (UML).
Object-Oriented
Programming
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.
Objects, which are usually instances of classes, are used to interact with one another to design
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 to as class data.
A set of operations that represent the behavior of the objects of the class.
Operations are also referred to as functions ormethods
Cntd…
E.g., 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
During instantiation, values are assigned for at least some of the attributes. If
depict its
we create an object my_circle, we can assign values like x-coord : 2, y-coord :
Encapsulation and Data
Hiding
Encapsulation
It 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 protecting an object’s data is called data hiding or information
hiding.
cntd…
Example
In the class Circle, data hiding can be incorporated by making attributes invisible
from
outside the class and adding two more methods to the class for accessing class
data, namely:
setValues(), method to assign values to x-coord, y-coord, and a
getValues(), method to retrieve values of x-coord, y-coord, and a
Here the private data of the object my_circle cannot be accessed directly by any
method that is not encapsulated within the class Circle.
It should instead be accessed through the methods setValues() and getValues().
Message Passing
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.
E.g., From a class Mammal, a number of classes can be derived such as Human,
Cat,
Dog, Cow,
Types of inheritance: The following are the types
inheritance
Single Inheritance : A subclass derives from a single super-class.
By minor, it is meant that these elements are useful, but not crucial part of
Booch has defined modularity as: “Modularity is the property of a system that has
been decomposed into a set of cohesive and loosely coupled modules.”
Modularity is essentially linked with encapsulation.
Abstraction in Programming is
Encapsulation means binding the code
about hiding unwanted details
and data into a single unit.
while showing most essential
information.
Hierarchy
In Grady Booch’s words, “Hierarchy is the ranking or ordering of
abstraction”.
Through hierarchy, a system can be made up of interrelated subsystems, which
can have their own subsystems and so on until the smallest level
components are reached.
It uses the principle of “divide and conquer”.
Persistence: An object occupies a memory space and exists for a particular period of time.
In traditional programming, the lifespan of an object was typically the lifespan of the
execution of the program that created it.
In files or databases, the object lifespan is longer than the duration of the process creating the object.
This property by which an object continues to exist even after its creator stops to exist is
known
as
Couplin
g
coupling is the degree of interdependence between software modules; a measure of
how closely connected two routines or modules are.
the strength of the relationships between modules.
I. Procedural programming
A module here refers to a subroutine of any kind.
Content coupling (high): Content coupling is said to occur when one module uses the code
of another module, for instance a branch. This violates information hiding: a basic software
design concept.
Common coupling: it is said to occur when several modules have access to the same global
data. But it can lead to uncontrolled error propagation and unforeseen side-effects when
changes are made.
Cntd…
Each datum is an elementary piece, and these are the only data shared (e.g., passing
an integer to a function that computes a square root).
Cntd…
Assembly of modules might require more effort and/or time due to the increased
inter- module dependency.
A particular module might be harder to reuse and/or test because dependent
modules
must be
Cohesion
Cohesion refers to the degree to which the elements inside a module belong
together.
In one sense, it is a measure of the strength of relationship between the methods
and
data of a class and some unifying purpose or concept served by that class.
Cohesion is an ordinal type of measurement and is usually described as “high
cohesion” or “low cohesion”.
Modules with high cohesion tend to be preferable, because high cohesion is
associated with several desirable traits of software including robustness,
reliability, reusability, and understandability.
In contrast, low cohesion is associated with undesirable traits such as being difficult
to maintain, test, reuse, or even understand.
Cntd…
Cohesion is often contrasted with coupling, a different concept.
High cohesion often correlates with loose coupling, and vice versa.
One can often estimate the degree of cohesion within a module by writing a
brief statement of the module's purpose.
If the sentence contains words relating to time, such as "first," "next," "then,"
"after," "when," or "start," the module probably has sequential or temporal binding.
An example is "Wait for the instant teller customer to insert a card, then
prompt for the personal identification number."
If the predicate of the sentence does not contain a single, specific object
following the verb, the module is probably logically bound. For example, "Edit all
data" has logical binding; "Edit source data" may have functional binding.
If the sentence contains words such as "Initialize" or "Clean up," the module
probably
has temporal binding.
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.
Polymorphism is an OOP concept that refers to the ability of a variable,
function, or object to take on multiple forms.
In a programming language exhibiting polymorphism, class objects belonging to
the same hierarchical tree (inherited from a common parent class) may have
functions with
the same name, but with different behaviors.
cntd…
Types of polymorphism:
Compile time
polymorphism Example:
Method overloading
Runtime polymorphism
Example: Method overriding
Advantages of polymorphism:
It helps programmers reuse code
and classes once written, tested,
and implemented.
A single variable name can be used to store variables of multiple data types
(float, double, long, int, etc).
Cntd…
Interfaces
All data should be hidden within a class.
make all data attributes private
provide public methods (accessor methods) to get and set the data values
e.g. Grade information is usually confidential, hence it should be kept private to the student.
Access
to the grade information should be done through interfaces, such as setGrade() and getGrde()