0% found this document useful (0 votes)
92 views

Unit 1 - Introduction To OOP

Structured programming divides programs into functions and modules, taking a top-down approach. However, it does not model real-world objects well by separating data from functions. Object-oriented programming combines data and functions into objects, taking a bottom-up approach. It emphasizes data over logic and divides programs into objects that can communicate through messages. The key concepts of OOP include classes, objects, encapsulation, inheritance, polymorphism and dynamic binding.

Uploaded by

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

Unit 1 - Introduction To OOP

Structured programming divides programs into functions and modules, taking a top-down approach. However, it does not model real-world objects well by separating data from functions. Object-oriented programming combines data and functions into objects, taking a bottom-up approach. It emphasizes data over logic and divides programs into objects that can communicate through messages. The key concepts of OOP include classes, objects, encapsulation, inheritance, polymorphism and dynamic binding.

Uploaded by

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

Introduction to OOP

Structured Programming
▪Emphasis on logic more than data or action
▪The steps of programming (algorithms) are more emphasized
▪C, Pascal, FORTRAN, and similar languages are procedural
languages i.e., each statement in the language tells the
computer to do something
▪A program in a procedural language is a list of instructions:
Get some input, add these numbers, divide by six, display that
output, and so on

Prepared by Sherin Joshi


Structured Programming
▪Also known as Modular Approach to Programming
▪Major Feature – Division into Functions
▪Dividing a program into functions and modules is one of the
cornerstones of structured programming
▪The idea of breaking a program into functions can be further
extended by grouping a number of functions together into a
larger entity called a module (which is often a file)
▪Top-down approach of program design

Prepared by Sherin Joshi


Procedure Oriented Programming

Prepared by Sherin Joshi


Structured Programming

Prepared by Sherin Joshi


Problems with Structured Programming
▪Unrestricted Access (of data)

Prepared by Sherin Joshi


Problems with Structured Programming
▪Local data is hidden inside a function, and is used exclusively
by the function
▪Local data is closely related to its function and is safe from
modification by other functions
▪However, when two or more functions must access the same
data then the data must be made global
▪Global data can be accessed by any function in the program
▪In a large program, there are many functions and many global
data items which leads to a large number of potential
connections
Prepared by Sherin Joshi
Problems with Structured Programming

Prepared by Sherin Joshi


Problems with Structured Programming
▪Real World Modeling
▪Arrangement of separate data and functions does a poor job
of modeling things in the real world
▪In the physical world we deal with objects such as people and
cars
▪Such objects aren’t like data and they aren’t like functions
▪Complex real-world objects have both attributes and
behavior

Prepared by Sherin Joshi


Problems with Structured Programming
▪Attributes (Characteristics)
▪For people, eye color, job title
▪For cars, horsepower and number of doors
▪Attributes are equivalent to data in a program: they have a
certain specific values, such as blue (for eye color) or four
(for the number of doors)

Prepared by Sherin Joshi


Problems with Structured Programming
▪Behavior
▪Behavior is something a real-world object does in response
to some stimulus
▪If you ask your boss for a raise, she will generally say yes or
no
▪If you apply the brakes in a car, it will generally stop
▪Behavior is like a function: you call a function to do
something (display the inventory, for example) and it does it
▪So neither data nor functions, by themselves, model
real-world objects effectively
Prepared by Sherin Joshi
Object Oriented Programming
▪Emphasis on data rather than steps or logic
▪Programs are divided into entities called objects
▪The fundamental idea behind object-oriented languages is to
combine into a single unit both data and the functions that
operate on that data
▪Data is hidden and cannot be accessed by external functions
and hence is safe from accidental alteration
▪Objects may communicate with each other through functions

Prepared by Sherin Joshi


Object Oriented Programming
▪New data and functions can be easily added whenever
necessary
▪Data encapsulation and data hiding are key terms in the
description of object-oriented languages
▪Bottom-up approach of program design

Prepared by Sherin Joshi


Prepared by Sherin Joshi
Prepared by Sherin Joshi
Prepared by Sherin Joshi
Prepared by Sherin Joshi
Basic Concepts / Characteristics of OOP
▪ Objects
▪ Classes
▪ Data Abstraction and Encapsulation
▪ Inheritance
▪ Polymorphism
▪ Dynamic Binding
▪ Message Passing

Prepared by Sherin Joshi


Objects
▪ Objects are basic run-time entities of an object oriented
system
▪ Program objects must be chosen such that they match closely
with real world objects
▪ They may represent a person, place, a bank account, a table
of data or any item that the program has to handle

Prepared by Sherin Joshi


Objects

Prepared by Sherin Joshi


Classes
▪ Class is a user defined data type
▪ An object is a instance of a class
▪ In simple terms, objects are variable of type class
▪ Once a class has been defined, we can create any number of
objects belonging to that class
▪ A class is thus a collection of objects of similar type
▪ For example, if ‘Brand’ has been defined as a class, then
Brand gucci;
will create an object gucci belonging to the class Brand
Prepared by Sherin Joshi
Classes

Prepared by Sherin Joshi


Prepared by Sherin Joshi
Data Abstraction and Encapsulation
▪ The wrapping up of data and functions into a single unit
(called class) is known as encapsulation
▪ The data is not accessible to the outside world, and only
those functions which are wrapped in the class can access it
▪ These functions provide the interface between the object’s
data and the program
▪ The insulation of data from direct access by the program is
called data hiding or information hiding

Prepared by Sherin Joshi


Data Abstraction and Encapsulation
▪ Abstraction refers to the concept of representing essential
features without including the background details or
explanations
▪ Classes use the concept of abstraction and are defined as a
list of abstract attributes (data members) and functions to
operate on these attributes (methods or member functions)
▪ Since the classes use the concept of data abstraction, they
are known as Abstract Data Types (ADT)

Prepared by Sherin Joshi


Inheritance
▪ Inheritance is the feature by which objects of one class
acquire the properties of objects of another class
▪ It supports the concept of hierarchical classification
▪ The concept of inheritance provides the idea of reusability
▪ This means we can add additional features to an existing class
without modifying it
▪ This is possible by deriving a new class from an existing one
▪ The new derived class will have the features of the existing
class as well as its own unique features

Prepared by Sherin Joshi


Inheritance

Prepared by Sherin Joshi


Prepared by Sherin Joshi
Prepared by Sherin Joshi
Polymorphism
▪ Polymorphism means the ability to take more than one form
▪ Using this feature, an operation may exhibit different behaviors in
different instances
▪ The behavior depends on the types of data used in the operation
▪ Example: Operator Overloading – Consider the addition
operation
▪ For two numbers, the operation would generate a sum
▪ For two strings, the operation would generate a third string which is
the concatenation of the two input strings
▪Another Example: Function Overloading
Prepared by Sherin Joshi
Polymorphism

Prepared by Sherin Joshi


Dynamic Binding
▪ Binding refers to the linking of a procedure call to the code to
be executed in response to the call
▪ Dynamic Binding (Late Binding) means the code associated
with a given procedure call is not known until the time of the
call at runtime
▪ It is associated with polymorphism and inheritance

Prepared by Sherin Joshi


Message Passing
▪ An object oriented program consists of a set of objects that
communicate with each other
▪ The process of programming in an object oriented language
involves the following steps:
▪Creating classes that define objects and their behavior
▪Creating objects from class definitions
▪Establishing communication among objects
▪Objects communicate with one another by sending and
receiving messages
Prepared by Sherin Joshi
Message Passing
▪ A message for an object is a request for execution of a
procedure and therefore will invoke a function (procedure) in
the receiving object that generates the desired result
▪ Message passing involves specifying the name of the object,
the name of the function (message) and the information to be
sent

Prepared by Sherin Joshi


Prepared by Sherin Joshi

You might also like