0% found this document useful (0 votes)
10 views42 pages

Oop Lect1

Uploaded by

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

Oop Lect1

Uploaded by

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

Presentation on OOP

(Object Oriented Programming)

Presented by
Engr. Muhammad Furqan
Lecturer IBET LUMHS
What is OOP ?
• A programming paradigm that is focused on objects and
data

• Objects are identified to model a system

• Objects are designed to interact with each other


Object-oriented programming (OOP) is a programming paradigm
using "objects" – data structures consisting of data fields and
methods together with their interactions – to design applications
and computer programs. Programming techniques may include
features such as data abstraction, encapsulation, messaging,
modularity, polymorphism, and inheritance
• Object-oriented programming (OOP) is a computer programming model that
organizes code around objects, rather than logic and functions. In OOP, programs
are made up of objects that can interact with each other, other programs, or the
user.
• Here are some characteristics of OOP:
• Reusability: OOP makes code more reusable.
• Efficiency: OOP makes programs more efficient.
• Scalability: OOP is scalable.
• Abstraction: OOP is based on abstract data types, a mathematical discipline for
storing data and the procedures to process it.
• Inheritance: OOP allows classes to inherit features from other classes.
• Simplicity: OOP simplifies application development by hiding lower-level coding
details.
• OOP is well suited for large, complex, and frequently updated software, such as
mobile apps and manufacturing and design programs.
• Here are some examples of objects in OOP:
• Human: A human can be described by properties like name and
address.
• Widget: A small computer program can be an object.
• Stereo system: A stereo system can be an object with a logic board
inside and buttons on the outside.
• Car: A car can have private variables like color, year, and model,
and a public method called Start.
• Employee: An employee object can define all the general
characteristics of employees in a company.
• Manager: A manager object can inherit the characteristics of the
employee object, but also add characteristics unique to managers.
Some OOP Languages
• C++ • Objective C
• Java • PHP 5
• C# • Python
• Java • JavaScript
• Visual Basic .NET • Smalltalk
• Theta
(VB.NET) • etc
Basic Concept Of Object Oriented
Programming
Objects
Classes
Data Abstraction
Encapsulation
Inheritance
Polymorphism
Dynamic Binding
Message Passing
Objects

• They may represent a person, a place or any item


that the program must handle.
• Objects are the basic run-time entities in an object-
oriented system An object is entity that has state,
behavior and identity . there are many.
• Every object is associated with data and functions
which define meaningful operations on that object.
• Object is a real world existing entity.
• Object is an Instance of a particular class.
Example

Mouse is
object
Behavior Scrolling

Left Right
Click Click
Class

• A class is an entity that helps the programmer to


define a new complex data type. A class defines
the data and behavior of object . In simple words ,
a class is a collection of object of similar type.
• Classes are user -defined data types and it
behaves like built in types of programming.
• objects are variables of class.
• Once A class has been defined we can create any
number of objects for that class.
Class : Fruit

Banana Apple Pineapple Strawberry


Data Abstraction

“A data abstraction is a simplified view of an


object that includes only features one is
interested in while hides away the
unnecessary details.”

“Data abstraction becomes an abstract data


type (ADT)or a user-defined type.”
Example

Program Execution Output

Hiding Of Data
And Its
Background
Detail
Python code of Data abstraction

Note:

The self parameter is a reference to the current instance of the


class, and is used to access variables that belongs to the class.
Encapsulation

• Encapsulation is the first pillar or principal


of object oriented programming.

• In simple words, "encapsulation is a process of


binding data members(variable, properties)and
member function(methods)into a single unit”

•And class is the best example of encapsulation.


Encapsulation
Encapsulation is one of the fundamental concepts in object-oriented
programming (OOP). It describes the idea of wrapping data and the
methods that work on data within one unit. This puts restrictions on
accessing variables and methods directly and can prevent the accidental
modification of data. To prevent accidental change, an object’s variable can
only be changed by an object’s method. Those types of variables are
known as private variables
.
A class is an example of encapsulation as it encapsulates all the data that is
member functions, variables, etc. The goal of information hiding is to
ensure that an object’s state is always valid by controlling access to
attributes that are hidden from the outside world.
Example,

Consider a real-life example of encapsulation, in a company, there are different


sections like the accounts section, finance section, sales section etc. The
finance section handles all the financial transactions and keeps records of all
the data related to finance. Similarly, the sales section handles all the sales-
related activities and keeps records of all the sales. Now there may arise a
situation when due to some reason an official from the finance section needs
all the data about sales in a particular month. In this case, he is not allowed to
directly access the data of the sales section. He will first have to contact some
other officer in the sales section and then request him to give the particular
data. This is what encapsulation is. Here the data of the sales section and the
employees that can manipulate them are wrapped under a single name “sales
section”. Using encapsulation also hides the data. In this example, the data of
the sections like sales, finance, or accounts are hidden from any other section.
Python code of encapsulation
Inheritance
•The mechanism of deriving a new class from an old
class is called inheritance or derivation.

•“Inheritance is the mechanism to provides the


power of reusability and extendibility.”

•“Inheritance is the process by which one object


can acquire the properties of another object.”

•The old class is known as base class while new


class is known as derived class or sub class
Example
Inheritance
Parent class
Or
Base class
Point

Child class
Or
Derived
class Line
• Inheritance allows us to define a class that
inherits all the methods and properties from
another class.
• Parent class is the class being inherited from,
also called base class. Child class is the class
that inherits from another class, also called
derived class.
Create a Parent Class
Polymorphism

• Polymorphism is an important object oriented


programming concept. This is a Greek term, means the

ability to take more than one form.


For Example

plus '+' is used to make sum of two number as well as


it is used to combine two strings.

Operator ‘+’

‘pak’+’istan’=p
5+5=10 akistan
Dynamic Binding

•Binding means link between procedure call and code

to be execute.

• It is the process of linking of a function call to the


actual code of the function at run-time.

•That is, in dynamic binding, the actual code to be


executed is not known to the compiler until run-time.

•It is also known late binding.


Massage Passing

• Objects can communicate with each others by passing


massage same as passing massage with each other.

• Objects can send or receive message or information.

• Message passing involves the following basic steps:


-Creating classes that define objects and their behavior.
-Creating objects from class definitions.
-Establishing communication among objects.
Example

consider two classes product and order. the object


of the product class can communicate with the
order class by sending a request for placing order.
Object :order1
order. place_order(qty_in_hand):
Order_place (int q)
Massage {
passing
Object name
}
Function or
massage Information
(Optional)
Message Passing
StudentObject FacultyObject

Performance

MgmtObject Performance
Result
Thank you

You might also like