chapter 1 basics of oop
TRANSCRIPT
-
8/2/2019 Chapter 1 Basics of OOP
1/20
OBJECT ORIENTED PROGRAMMING AND
GRAPHICS LABORATORY (OOPCG)
Examination Scheme
Practical: 50 marks
Term Work: 50 marks
-
8/2/2019 Chapter 1 Basics of OOP
2/20
Syllabus
UNIT-I: Introduction to Object Oriented Programming
UNIT-II: Programming with C++
UNIT-III: Classes and Objects
UNIT-IV: Operator OverloadingUNIT-V: Inheritance and Polymorphism
UNIT-VI: Templates
UNIT-VII: Exception Handling
UNIT-VIII: Files and Streams
-
8/2/2019 Chapter 1 Basics of OOP
3/20
ext Books:
. Balaguruswamy, Object Oriented Programming with C++,
Tata
cGraw-Hill Publishing Company Ltd, New Delhi ISBN 0 07
462038 X.Reference Books:
R. Lafore, The Waite Groups Object oriented Programming in
C++, 3rdEdition, Galgotia Publications, 2001, ISBN 81-7515-269-9.
-
8/2/2019 Chapter 1 Basics of OOP
4/20
nowledge of C Language
-
8/2/2019 Chapter 1 Basics of OOP
5/20
What is OOP?OOP is a design philosophy. It stands for Object Oriented
Programming.
Object-Oriented Programming (OOP) uses a different set of
programming languages than old procedural programminglanguages (C, Pascal, etc.).
eys of OOP
-
8/2/2019 Chapter 1 Basics of OOP
6/20
What is Procedural Programming Languages/Procedure
oriented Programming (POP) ? Conventional programming, using high level languages.
Sequence of things.
Number of functions.
eys of OOP
Technique of hierarchical decomposition has been used to specify the tasks to be
completed for solving the problem
-
8/2/2019 Chapter 1 Basics of OOP
7/20
What is Procedural Programming Languages/Procedure
oriented Programming (POP) ? Concentration on the development of function.
What about data?
eys of OOP
Data items are placed global.
Global data are vulnerable to an inadvertent change by a function.
-
8/2/2019 Chapter 1 Basics of OOP
8/20
Drawbacks of Procedural Programming Languages/Procedure
oriented Programming (POP) Large program , difficult to identify what data is used by what
function.
Revise an external data structure, revise all functions that
access the data, bugs to creep in. Doesn't model real life problems very well.
Functions are action-oriented and do not really
corresponds to the elements of the problem.
eys of OOP
-
8/2/2019 Chapter 1 Basics of OOP
9/20
eys of OOP
-
8/2/2019 Chapter 1 Basics of OOP
10/20
Object Oriented Paradigm
Motivating factor is to remove the flaws in the POP.
OOP treats data as the critical element in the program
development , does not allow to flow freely around the
system.
Decomposition of the problem into a number of entities
called objects and then built data and function around these
object.
eys of OOP
-
8/2/2019 Chapter 1 Basics of OOP
11/20
eys of OOP
-
8/2/2019 Chapter 1 Basics of OOP
12/20
anguages that are based on classes are know as Object-Oriented.
Eiffel
C++
Modula-3
Ada 95
Java
eys of OO Programming
-
8/2/2019 Chapter 1 Basics of OOP
13/20
Object Oriented Programming as an approach that
provides a way of modularizing programs by creating
partitioned memory area for both data and function that
can be used as template for creating copies of such
modules on demand
-
8/2/2019 Chapter 1 Basics of OOP
14/20
oncepts used extensively in OOP
Objects
Classes
Data abstraction and encapsulation
Inheritance
Polymorphism
Dynamic binding
Message passing
asics of OOP
-
8/2/2019 Chapter 1 Basics of OOP
15/20
Objects Objects are the basic run-time entities in an object-oriented system.
Used to represent any data item that the program has to handle.
Object take up space in the memory and have a associated addresslike a record in Pascal or a structure in C.
When a program is executed the object interact by sending msg to
one another. Each object contain data , and code to manipulate the data.
Object can interact without having to know details of each othersdata or code.
asics of OOP
-
8/2/2019 Chapter 1 Basics of OOP
16/20
Classes Entire set of data and code of an object can be made a user-defined
data types with the help of a class.
Object are variable of the type class.
Any number of objects can be created of that class.
Classes are user-defined data types and behave like the built-in types
of a programming language. Class is thus a collection of objects of similar type.
For example: mango, apple, banana and orange are members of theclass fruit.
Syntax used:
Fruit mango;
asics of OOP
-
8/2/2019 Chapter 1 Basics of OOP
17/20
Data Abstraction and Encapsulation The wrapping up of data and function into a single unit (called class)
is known as encapsulation.
Is the most striking feature of a class.
The data is not accessible to outside world, and only those functionwhich are wrapped in the class can access it.
This insulation of the data from direct access by the program is calledas data hiding or information hiding.
Data abstraction refers to, providing only essential information to theoutside word and hiding their background details ie. to represent theneeded information in program without presenting the details.
Data abstraction is a programming (and design) technique that relieson the separation of interface and implementation.
asics of OOP
-
8/2/2019 Chapter 1 Basics of OOP
18/20
Inheritance Is the process by which objects of one class acquire the properties of
objects of another class.
It supports the concept of hierarchical classification.
asics of OOP
The principle behind this sort of
division is that each derived class
shares common characteristics with
the class from which it is derived.
Provides an opportunity to reuse
the code functionality and fast
implementation time.
When creating a class, instead ofwriting completely new data
members and member functions, the
programmer can designate that the
new class should inherit the
members of an existing class.
-
8/2/2019 Chapter 1 Basics of OOP
19/20
Polymorphism Greek term, means the ability to take more than one form. An operation may exhibit different behaviours in different instances
Behaviour depends upon the types of data used in operations.
The process of making an operator to exhibit different behaviours indifferent instances is known as operator overloading
Polymorphism is extensively used in implementing inheritance.
asics of OOP
-
8/2/2019 Chapter 1 Basics of OOP
20/20
What is OOP?
OOP is a design philosophy. It stands for Object OrientedProgramming. Object-Oriented Programming (OOP) uses a different
set of programming languages than old procedural programminglanguages (C, Pascal, etc.). Everything in OOP is grouped as selfsustainable "objects". Hence, you gain re-usability by means of fourmain object-oriented programming concepts.
In order to clearly understand the object orientation, lets take yourhand as an example. The hand is a class. Your body has twoobjects of type hand, named left hand and right hand. Their mainfunctions are controlled/ managed by a set of electrical signals sentthrough your shoulders (through an interface). So the shoulder is aninterface which your body uses to interact with your hands. Thehand is a well architected class. The hand is being re-used to createthe left hand and the right hand by slightly changing the propertiesof it.