[go: up one dir, main page]

0% found this document useful (0 votes)
6 views43 pages

1 Oop

oops in c++

Uploaded by

rajulauru6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views43 pages

1 Oop

oops in c++

Uploaded by

rajulauru6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 43

Chapter-1

Introduction to Object
Oriented
Programming

SUSHANT BHATTARAI
1. 1 Software
Evolution

SUSHANT BHATTARAI
Software Evolution 3

 Evolution is the gradual development.


 Software is also evolving from what it was
before, representing and being an integral part
of our real world.
1.2 Basics of Object
Oriented
Programming

SUSHANT BHATTARAI
5

Procedure oriented
programming
 Each statement tells the computer to do
something.
 Programs are list of statements(procedures)
 Fine for easy and small programs.
6

Procedure oriented
programming
 When a program becomes large, such
paradigm(method) becomes ineffective.
 For this the program was broken down into
functions and modules.(Structure)
 Structured programming was popular for some
decades.
7

Procedure oriented
programming
 As programs grew larger, structured
programming also became ineffective.
 Google The Mythical Man-Month for details.
 The problem is with the procedure oriented
programming paradigm.
 No matter how well structured programming is
implemented, large programs become
excessively complex.
8
Problems with Procedure Oriented
Programming
 Consider an example of an inventory program.
 One important global data is collection of items
in the inventory.
 Various functions access this data to input a
new item, display an item, modify an item etc.
9
Problems with Procedure Oriented
Programming-Unrestricted Access
1
Problems with Procedure Oriented 0
Programming-Unrestricted Access

 Large program has many functions and many


global data items.
1
Problems with Procedure Oriented 1
Programming-Unrestricted Access

 Program will be hard to conceptualize.


 It will be even harder to modify.
 Eg: in that inventory system, if someone
decides to change product code from 5 digits to
12 digits, think what will happen?
 And if the program is large, it will be hard to tell
which function accesses which data.
1
Problems with Procedure Oriented 2
Programming-Real World Modeling

 Procedural paradigm arranges data and


function separately.
 Hence, it models real world poorly.
 Real objects aren’t like data and functions. They
have attributes and behaviors.
 Attributes are like data and behaviors are like
functions.
1
Problems with Procedure Oriented 3
Programming-Real World Modeling

 So, neither data nor functions by themselves


model real world perfectly.
1
Problems with Procedure Oriented 4
Programming-New Data Types

 Difficulty in creating new data type.


 Example – Coordinate system.
 Results in complexity while writing and
maintainence.
1
Object Oriented Programming 5

 The fundamental idea in object-oriented


programming is to combine both data and the
functions that operate on the data into a
single unit called object.
 Data of an object is accessible by the function
of the object.
1
Object Oriented Programming 6

 You cannot access the data directly.


 Data and functions are encapsulated.
 If you want to modify the data in an object, you
know exactly which functions interact with it.
 This simplifies writing, debugging and
maintaining the program.
1
Object Oriented Programming 7
1
Object Oriented Programming- An 8
Analogy
 Can think of objects as departments in
a company.
 Sales, marketing, accounting, HR etc.
 Each department has it’s own
personnel.
 Also has it’s own data
 The people in each department control
and operate on that department’s data.
 Dividing the company into departments
makes it’s easier to comprehend and
control the company’s activities.
1
Object Oriented Programming- An 9
Analogy
 If you are a sales manager and want to
know about salaries paid in January then
 You don’t just go into accounting
department and start looking at files.
 You will request a person who works on the
accounting department for that data and
he/she will provide you with the details.
 This ensures data is accessed accurately
and that it is not corrupted by inept
outsiders.
 In the same way, Objects will provide
efficient mechanisms to handle company’s
data efficiently ensuring it’s integrity.
2
Object Oriented Programming 0

 Keep in mind that an OOP program may look


like a program written in procedural language.
 It just differs in the bigger picture, about overall
organization.
Assignment #1 2
1

 Procedure Oriented Vs Object Oriented


Programming.
1.3 Elements of
Object Oriented
Programming

SUSHANT BHATTARAI
Object 2
3

 Problem is divided into objects in OOP.


 Program can be designed easily and effectively.
 Models real world well.
 Object consist of data and set of functions that
operate on the data.
Object 2
4

 What kind of things become object?


 Humans like students, employees etc.
 Physical objects like automobiles in a
traffic flow simulation, electrical
components in a circuit program,
airplanes in air traffic program,
countries in an economic model etc.
 Elements of computer like windows,
menu, mouse etc.
Classes 2
5

 Objects are the member of classes.


 A class is like a plan of how an object will be.
 It specifies what data and functions will be
included in the object of the class.
 Defining the class doesn’t create any objects.
Classes 2
6

 Bipul Chettri, Narayan Gopal etc. are objects of


class called musicians.
 There is no one person called musician but
specific people with specific names are member
of this class if they possess certain
characteristics.
Encapsulation 2
7

 Data and functions that operate on the data are


encapsulated in a single entity called Object.
Abstraction 2
8

 You cannot access the data directly.


 It is hidden.
 To access and modify the data, you need to
interface with the function that interact with it.
 Abstraction refers to an act of representing
essential features without including ground
details or explanations.
Inheritance 2
9

 Idea of class leads to inheritance.


 Class of animals contain mammals, insects etc.
 Class of vehicle consists of cars, trucks, buses
etc.
 The principle is that each subclass shares
common characteristics with the class from
which it is derived.
Inheritance 3
0

 Features A and B, which are part of base class, are common to


all derived classes, but that each derived class also has a
feature of it’s own.
Inheritance 3
1
 InOOP, a class can be divided into
subclasses.
 Original Class is called a base class and
other classes formed from base class are
called derived classes.
Reusability 3
2
 Oncea class has been written, tested and
debugged, it can be distributed to other
programmers for use in their own
languages.
 This is called Reusability.
 Concept of inheritance provides an
important extension to the idea of
reusability.
Polymorphism and 3
3
Overloading
 Polymorphism means having many forms.
 Using operators or functions in different ways,
depending on what they are operating on, is
called Polymorphism.
Dynamic binding 3
4

 It is the process of connecting the method call


to the specific method at runtime.
 The compiler decides which method should be
called for a particular call during runtime.
Message Passing 3
5

 Sending and receiving of information by the


objects same as people exchange information.
 This helps in building systems that simulate real
life.
1.4 Object Oriented
Languages.

SUSHANT BHATTARAI
OOP Languages 3
7

 C++
 Smalltalk
 Java
 C#.net
 Python etc.
1.5 Advantages and
Disadvantages of OOP

SUSHANT BHATTARAI
OOP Good or Bad? 3
9

 Main idea to create OOP was to remove some of


the major disadvantages of the procedural
programming approach.
 OOP is revolutionary idea, yet it has some
disadvantages.
 Pros weigh out the cons.
Advantages of OOP 4
0

 Programs written with OOP are really easy


to understand.
 Since, everything is treated as objects, we
can model a real-world concept very well.
 OOP approach offers reusability of classes.
We can reuse the classes that are already
created without writing them again and
again .
 Program can be modular. Easy to create,
test, debug and maintain.
 Data abstraction is achieved.
Disadvantages of OOP 4
1

 Sometimes the relation among classes gets


artificial.
 Designing a program in OOP concept is a bit
tricky.
 Extra skills is required.
 Size of program will be comparatively larger.
 Larger program results in slower execution as
more instruction needs to be executed.
Summary 4
2

 OOP is a way of organizing programs.


 The emphasis is on the way programs are
designed, not on coding details.
 Object consists of both data and functions that
operate on the data.
 Abstraction means data hiding.
 Encapsulation means binding data and
functions together.
Summary 4
3

 Code can be reusable with the concept of


classes and inheritance.
 Polymorphism is also an important feature.

You might also like