OOPM
(Object Oriented Programming & Methodology )
Subject Code CS-305
Ms. Poorva Shukla.
CSE Department
Ms.Poorva Shukla
Unit –I
Content
Introduction to Object Oriented Thinking &
Object Oriented Programming: Comparison
with Procedural Programming, features of
Object oriented paradigm–Merits and demerits
of OO methodology; Object model; Elements
of OOPS, IO processing.
Ms.Poorva Shukla
Introduction to Object Oriented Thinking &
Object Oriented Programming
• Traditionally, a programming problem is attacked by coming up
with some kinds of data representations, and procedures that operate
on that data.
• Under this model, data is inert, passive, and helpless; it sits at the
complete mercy of a large procedural body, which is active, logical,
and all-powerful.
• As a project gets larger, its procedural core grows to the point where
it is difficult to remember how the whole thing works.
• There are guidelines for programming that can help to minimize and
localize bugs within this traditional paradigm, but there is a better
solution that involves fundamentally changing the way we work
Ms.Poorva Shukla
What is abstract interaction?
Ms.Poorva Shukla
OOP(Object Oriented Programming)
• Object-oriented programming (OOP) is a programming
paradigm based on the concept of "objects", which can contain data,
in the form of fields (often known as attributes or properties), and
code, in the form of procedures (often known as methods).
• Many of the most widely used programming languages (such as
C++, Java, Python, etc.) are multi-paradigm and they support object-
oriented programming
• Object Oriented Methodology (OOM) is a system development
approach encouraging and facilitating re-use of software
components.
Ms.Poorva Shukla
Benefits of object-oriented
technology include:
• Ease of software design
• Productivity
• Easy testing, debugging, and maintenance
• It’s reusable
• More thorough data analysis, less development time, and
more accurate coding, thanks to OOP’s inheritance method
• Data is safe and secure, with less data corruption, thanks to
hiding and abstraction.
• It’s sharable (classes are reusable and can be distributed to
other networks).
Ms.Poorva Shukla
Ms.Poorva Shukla
OBJECT ORIENTED PROCEDURE ORIENTED POINTS TO BE DISCUSSES
PROGRAMMING PROGRAMMING
1. In OOP, program is 1. In POP, program is 1. Divided Into
divided into parts divided into small parts
called objects. called functions.
2. In OOP, Importance is 2. In POP, Importance is
given to the data rather not given Importance 2. IMPORTANCE
than procedures or to data but to functions
functions because it as well as sequence of
works as a real world. actions to be done.
3. OOP follows Bottom Up 3. POP follows Top Down
approach. approach. 3. APPROACH
1. OOP has access 1. POP does not have any 1. Access
specifies named Public, access specified. 2. Specifies
Private, Protected, etc. 2. In POP, Data can move
2. In OOP, objects can freely from function to
move and function in the system. 3. Data Moving
communicate with 3. To add new data and
each other through function in POP is not
member functions. so easy. 4. Expansion
3. OOP provides an easy
way to add new data Ms.Poorva Shukla
and function.
Differences cont…..
OBJECT ORIENTED PROCEDURE ORIENTED POINTS TO BE DISCUSSES
PROGRAMMING PROGRAMMING
1. OOP provides Data 1. POP does not have any 1. Data hiding
Hiding so provides proper way for hiding
more security. data so it is less secure.
2. In OOP, overloading is 2. In POP, Overloading is
possible in the form of not possible. 2. Overloading
Function Overloading
and Operator
Overloading. 3. Example of POP is: C,
3. Example of OOP is: VB, FORTRAN,
C++, JAVA, VB.NET, Examples and Pascal 3. Example
C#.NET.
Ms.Poorva Shukla
Features of Object oriented paradigm
Object
Classes
Abstraction
Encapsulation
Inheritance
Polymorphism
Ms.Poorva Shukla
Object
Objects. Any real world
entity which can have
some characteristics or
which can perform some
tasks is called as Object.
This object is also called
an instance i.e. a copy
of entity in programming
language.
Ms.Poorva Shukla
Classes
• A class in OOP is a plan which describes the object.
• We call it a blueprint of how the object should be represented.
• Mainly a class would consist of a name, attributes, and operations.
Example :- The Mobile can be a class, which has some attributes like
Profile Type, IMEI Number, Processor, and some more. It can have
operations like Dial, Receive and Send Message.
Ms.Poorva Shukla
Class cont…
• SRP (The Single Responsibility Principle) - A class should have one,
and only one responsibility
• OCP (The Open Closed Principle) - You should be able to extend a
classes behavior, without modifying it. (Inheritance)
• LSP (The Liskov Substitution Principle) - Derived classes must be
substitutable for their base classes. (Polymorphism)
• ISP (The Interface Segregation Principle) -Make fine chopped
interface instead of huge interface as client cannot be forced to
implement an interface which they don't use.
• DIP (The Dependency Inversion Principle) - Depend on
abstractions, not on concretions. (Abstraction)
Ms.Poorva Shukla
Abstraction
• Data abstraction refers to, providing only
essential information to the outside world and
hiding their background details, i.e., to
represent the needed information in program
without presenting the details.
• For example, a database system hides certain
details of how data is stored and created and
maintained.
Ms.Poorva Shukla
#include <iostream>
using namespace std;
Abstraction in c++
class implementAbstraction
{
private: int main()
int a, b; {
implementAbstraction
public: obj;
obj.set(10, 20);
// method to set values of obj.display();
// private members return 0;
void set(int x, int y) }
{
a = x;
b = y;
}
void display()
{
cout<<"a = " <<a << endl;
cout<<"b = " << b << endl;
}
};
Ms.Poorva Shukla
Advantages of Data Abstraction:
• Helps the user to avoid writing the low level code
• Avoids code duplication and increases reusability.
• Can change internal implementation of class independently without
affecting the user.
• Helps to increase security of an application or program as only
important details are provided to the user.
Ms.Poorva Shukla
Encapsulation
• Encapsulation is placing the data and the functions that work on that
data in the same place.
• While working with procedural languages, it is not always clear
which functions work on which variables but object-oriented
programming provides you a framework to place the data and the
relevant functions together in the same object.
Ms.Poorva Shukla
Ms.Poorva Shukla
#include <iostream>
using namespace std;
class EncapsulationExample {
private:
// we declare a as private to hide it from outside
int a;
public: int main()
// set() function to set the value of a {
void set(int x) EncapsulationExample e1;
{
a = x; e1.set(10);
}
cout<<e1.get();
// get() function to return the value of a return 0;
int get() }
{
return a;
}
};
Ms.Poorva Shukla
Encapsulation cont…
• In the above program the variable x is made private. This variable
can be accessed and manipulated only using the functions get() and
set() which are present inside the class. Thus we can say that here,
the variable x and the functions get() and set() are binded together
which is nothing but encapsulation.
Ms.Poorva Shukla
Ms.Poorva Shukla
Inheritance
• Inheritance is the ability to extend the functionality from base entity
in new entity belonging to same group. This will help us to reuse the
functionality which is already defined before and extend into a new
entity.
• Considering the example, the above figure 1.1 itself shows what is
inheritance. Basic Mobile functionality is to send a message, dial
and receive a call. So the brands of mobile is using this basic
functionality by extending the mobile class functionality and adding
their own new features to their respective brand.
Ms.Poorva Shukla
Polymorphism
• The word polymorphism means having many forms. ... Real life
example of polymorphism: A person at the same time can have
different characteristic. Like a man at the same time is a father, a
husband, an employee. So the same person posses different
behaviour in different situations.
Ms.Poorva Shukla
ADVANTAGES of OOPM
• Focuses on data rather than the procedures as in
Structured Analysis.
• The principles of encapsulation and data hiding help
the developer to develop systems that cannot be
tampered by other parts of the system.
• It can be upgraded from small to large systems at a
greater ease than in systems following structured
analysis.
• Faster development
• Lower cost of development
• Higher-quality software
Ms.Poorva Shukla
Disadvantages of OOPM
1. Steep learning curve:
2. Larger program size:
3. Slower programs
4. Not suitable for all types of problems:
Ms.Poorva Shukla
omt
Ms.Poorva Shukla
Object Model
• An object model is a logical interface, software or system that is
modeled through the use of object-oriented techniques. It enables
the creation of an architectural software or system model prior to
development or programming
• An object model is part of the object-oriented programming (OOP)
lifecycle.
• An object model helps describe or define a software/system in
terms of objects and classes. It defines the interfaces or interactions
between different models, inheritance, encapsulation and other
object-oriented interfaces and features.
Ms.Poorva Shukla
Examples
• Document Object Model (DOM):
A set of objects that provides a modeled representation of dynamic
HTML and XHTML-based Web pages
• Component Object Model (COM):
A proprietary Microsoft software architecture used to create software
components
Ms.Poorva Shukla
Elements used in oopm
• The conceptual framework of object–oriented systems is based
upon the object model. There are two categories of elements in an
object-oriented system −
• Major Elements
• Minor Elements
Ms.Poorva Shukla
Major Elements − By major, it is meant that if a model does not
have any one of these elements, it ceases to be object oriented.
The four major elements are−
• Abstraction
• Encapsulation
• Modularity
• Hierarchy
Minor Elements − By minor, it is meant that these elements are
useful, but not indispensable part of the object model. The three
minor elements are −
• Typing
• Concurrency
• Persistence
Ms.Poorva Shukla
Modularity
• Modularity is the process of decomposing a problem (program) into
a set of modules so as to reduce the overall complexity of the
problem. 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 intrinsically linked with encapsulation. Modularity
can be visualized as a way of mapping encapsulated abstractions
into real, physical modules having high cohesion within the
modules.
Ms.Poorva Shukla
Hierarchy
“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”. Hierarchy allows code reusability.
• “IS–A” hierarchy
• “PART–OF” hierarchy
Ms.Poorva Shukla
• “IS–A” hierarchy
It defines the hierarchical relationship in inheritance, whereby from
a super-class, a number of subclasses may be derived which may
again have subclasses and so on. For example, if we derive a class
Rose from a class Flower, we can say that a rose “is–a” flower.
• “PART–OF” hierarchy
It defines the hierarchical relationship in aggregation by which a
class may be composed of other classes. For example, a flower is
composed of sepals, petals, stamens, and carpel. It can be said that a
petal is a “part–of” flower.
Ms.Poorva Shukla