SlideShare a Scribd company logo
OBJECT-ORIENTED PROGRAMMING
(OOP)
Ahmad Karawash
OUTLINE
• Definitions
• Classes & Objects
• OOP concepts
• Pros & Cons
2
OBJECT-ORIENTED PROGRAMMING (OOP)
3
DEFINITION
• OOP is mainly a program design philosophy.
• Key idea: The real world can be “accurately” described as a collection of
objects that interact.
• Everything is grouped as self sustainable "objects". Hence, you gain
reusability by means of four main OOP concepts.
4
Object-Oriented Programming (OOP)
OOP BASIC TERMINOLOGY
• Object - usually a person, place or thing (a noun)
• Method - an action performed by an object (a verb)
• Property or attribute - Characteristics of certain object.
• Class - a category of similar objects (such as automobiles), does not hold
any values of the object’ s attributes/properties
5
Object-Oriented Programming (OOP)
OPERATIONS/METHODS
• In OOP, programmers define not only the data type of a data structure, but
also the types of operations/methods (functions) that can be applied to the
data structure.
• In this way, the data structure becomes an object that includes both data
and functions (methods) in one unit. In addition, programmers can create
relationships between one object and another.
• For example, objects can inherit characteristics from other objects.
6
Object-Oriented Programming (OOP)
OOP LANGUAGES
• Pure OO Languages
• Ruby, Python, Scala, JADE.
• Hybrid OO Languages
• Delphi, C++, Java, C#, VB.NET, Pascal, Visual Basic, MATLAB, Fortran, Perl,
COBOL, PHP.
7
Object-Oriented Programming (OOP)
CLASSES & OBJECTS
8
DEFINITIONS
• A class is a prototype, idea, and blueprint for creating objects.
• For example, in Java we define classes, which in turn are used to create
objects
• A class has a constructor for creating objects
• Class is composed of three things: its name, attributes/properties, and
methods.
• Each copy of an object from a particular class is called an instance of the
class.
• The act of creating a new instance of a class is called instantiation.
9
Classes & Objects
CLASSES V.S. OBJECTS
• A class is a definition of objects with the same properties and the same
methods.
• An object is an instance of a class
10
Classes & Objects
TECHNICAL CONTRAST BETWEEN
OBJECTS & CLASSES
Object is a class in “runtime”
11
Classes & Objects
ALMOST EVERYTHING IN THE WORLD
CAN BE REPRESENTED AS AN OBJECT
• A flower, a tree, an animal
• A student, a professor
• A desk, a chair, a classroom, a building, etc.
12
Classes & Objects
IN SHORT
An Object is a Class when it comes alive!
• Homo Sapien is a class, John and Jack are objects
• Animal is a class, the cat is an object
• Vehicle is a class, my neighbor's BMW is an object
• Galaxy is a class, the MilkyWay is an object
13
Classes & Objects
OBJECTS NEED TO COLLABORATE!
• Objects are useless unless they can collaborate to solve a problem.
• Each object is responsible for its own behavior and status.
• No one object can carry out every responsibility on its own.
14
Classes & Objects
HOW DO OBJECTS INTERACT WITH
EACH OTHER?
15
Classes & Objects
EXAMPLE OF OBJECT
INTERACTION
The OrderEntryForm wants Order to calculate the total CAD value for the
order.
16
Classes & Objects
OOP CONCEPTS
17
OOP FOUR MAIN CONCEPTS
Encapsulation
Inheritance
Abstraction
Polymorphism
18
OOP Concepts
OOP CONCEPTS - ENCAPSULATION
19
ENCAPSULATION DEFINITION
• Is the inclusion of property & method within a class/object in which it needs
to function properly.
• Also, enables reusability of an instant of an already implemented class within
a new class while hiding & protecting the method and properties from the
client classes.
20
OOP concepts - Encapsulation
ENCAPSULATION WITH CLASSES
• The class is kind of a container or capsule or a cell, which encapsulate the
set of methods, attributes and properties to provide its indented
functionalities to other classes.
• In that sense, encapsulation also allows a class to change its internal
implementation without hurting the overall functioning of the system.
• That idea of encapsulation is to hide how a class does its operations while
allowing requesting its operations.
21
OOP concepts - Encapsulation
ENCAPSULATION IN ACTION
Example:
Let’s say we have a class called “Date” (day, month, year). And then you
need to define another class called “Person” that has the following attributes
(first name, last name, and birthdate). So in this case we can instantiate an
object from class “Date” inside class “Person”
22
OOP concepts - Encapsulation
Date
Person
ENCAPSULATION – BENEFITS
• Ensures that structural changes remain local:
• Changing the class internals does not affect any code outside of the class
• Changing methods' implementation does not reflect the clients using them
• Encapsulation allows adding some logic when accessing client's data
• E.g. validation on modifying a property value
• Hiding implementation details reduces complexity -> easier maintenance
23
OOP concepts - Encapsulation
OOP CONCEPTS - INHERITANCE
24
INHERITANCE DEFINITION
• Term comes from inheritance of traits like eye color, hair color, and so on.
• Classes with properties in common can be grouped so that their common
properties are only defined once in parent class.
• Superclass – inherit its attributes & methods to the subclass(es).
• Subclass – can inherit all its superclass attributes & methods besides having its
own unique attributes & methods.
25
OOP concepts - Inheritance
INHERITANCE PARENT/CHILD
• Inheritance allows child classes to inherit the characteristics of existing parent
class
• Attributes (fields and properties)
• Operations (methods)
• Child class can extend the parent class
• Add new fields and methods
• Redefine methods (modify existing behavior)
26
OOP concepts - Inheritance
INHERITANCE BENEFITS
• Expresses commonality among classes/objects
• Allows code reusability
• Highlights relationships
• Helps in code organization
27
OOP concepts - Inheritance
INHERITANCE EXAMPLE
28
OOP concepts - Inheritance
EXAMPLE: SINGLE INHERITANCE
One class inherits from another.
29
OOP concepts - Inheritance
EXAMPLE: MULTIPLE INHERITANCE
A class can inherit from several other classes.
Most modern languages don’t support multiple
inheritance!
30
OOP concepts - Inheritance
OOP CONCEPTS - ABSTRACTION
31
ABSTRACTION DEFINITION
• Abstraction is a basic representation of a concept.
• It is the process of removing characteristics from something in order to
reduce it to a set of essential characteristics.
• Through the process of abstraction, a programmer hides all but the relevant
data about a class in order to reduce complexity and increase reusability.
32
OOP concepts - Abstraction
ABSTRACTION BENEFITS
• Abstraction allows programmers to represent complex real world in the
simplest manner.
• It represent the necessary features an object should possess without
representing the background details.
• It allow ease reusability and understanding for the design and enable
extension.
33
OOP concepts - Abstraction
ABSTRACT CLASS
• An abstract class, which declared with the “abstract” keyword, cannot be
instantiated.
• It can only be used as a super-class for other classes that extend the
abstract class. Abstract class is a design concept and implementation gets
completed when it is being realized by a subclass.
34
OOP concepts - Abstraction
TYPE OF CLASSES
Concrete Class Abstract Class
Can be instantiated directly Cannot be instantiated directly
35
OOP concepts - Abstraction
ABSTRACTION + INHERITANCE
Concrete Class
Abstract Class
Can be instantiated directly
Cannot be instantiated directly
Person
Teacher Student
DOB:
Name:
Address:
Specialization:
Academic Title:
Etc…:
DOB:
Name:
Address:
GPA:
Courses:
Etc…:
DOB
Name
Address
Can be instantiated directly
36
OOP concepts - Abstraction
ABSTRACT CLASS: INSTANCE &
OPERATION
• An abstract class is a class that may not have any direct instances.
• An abstract operation is an operation that it is incomplete and requires a
child to supply an implementation of the operation.
37
OOP concepts - Abstraction
OOP CONCEPTS - POLYMORPHISM
38
POLYMORPHISM DEFINITION
• Polymorphisms is a generic term that means 'many shapes’.
• More precisely Polymorphisms means the ability to request that the same
methods be performed by a wide range of different types of things.
• It is achieved by using many different techniques named method
overloading, operator overloading, and method overriding.
39
OOP concepts - Polymorphism
POLYMORPHISM TRAITS
• An object has “multiple identities”, based on its class inheritance tree
• It can be used in different ways
40
OOP concepts - Polymorphism
POLYMORPHISM METHODS
• In Java, two or more classes could each have a method called output.
• Each output method would do the right thing for the class that it was in.
• One output might display a number (output.number) in one class, whereas it
might display a name (output.text) in another class.
41
OOP concepts - Polymorphism
POLYMORPHISM + ABSTRACT
CLASS EXAMPLE
Shape
method Draw()
Circle
Circle.Draw()
Triangle
Triangle.Draw()
Square
Square.Draw()
42
OOP concepts - Polymorphism
PROS & CONS
43
OOP PROS
• Code reuse & recycling
• Improved software-development productivity
• Improved software maintainability
• Faster development
• Lower cost of development
• Higher-quality software
• Encapsulation
44
Conclusion
OOP CONS
• Steep learning curve
• Could lead to larger program sizes
• Could produce slower programs
45
Conclusion
Ad

Recommended

Oop
Oop
志明 陳
 
Object Oriented Programming ppt presentation
Object Oriented Programming ppt presentation
AyanaRukasar
 
object oriented programming(oops)
object oriented programming(oops)
HANISHTHARWANI21BCE1
 
Introduction to OOP concepts
Introduction to OOP concepts
Ahmed Farag
 
Overloading vs Overriding.pptx
Overloading vs Overriding.pptx
Karudaiyar Ganapathy
 
Object-Oriented Programming Concepts
Object-Oriented Programming Concepts
Kwangshin Oh
 
Chapter 05 classes and objects
Chapter 05 classes and objects
Praveen M Jigajinni
 
concept of oops
concept of oops
prince sharma
 
Object oriented programming
Object oriented programming
Amit Soni (CTFL)
 
Object Oriented Language
Object Oriented Language
dheva B
 
Oop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
Polymorphism in java
Polymorphism in java
Elizabeth alexander
 
An Introduction to Drupal
An Introduction to Drupal
Tobias Ratschiller
 
object oriented Programming ppt
object oriented Programming ppt
Nitesh Dubey
 
Oops
Oops
Sankar Balasubramanian
 
Object oriented programming interview questions
Object oriented programming interview questions
Keet Sugathadasa
 
Introduction to oop
Introduction to oop
colleges
 
Python-Encapsulation.pptx
Python-Encapsulation.pptx
Karudaiyar Ganapathy
 
OOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptx
Mohamed Essam
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
Glenn Guden
 
Python - object oriented
Python - object oriented
Learnbay Datascience
 
Chapter 07 inheritance
Chapter 07 inheritance
Praveen M Jigajinni
 
OOPS Basics With Example
OOPS Basics With Example
Thooyavan Venkatachalam
 
C# File IO Operations
C# File IO Operations
Prem Kumar Badri
 
Introduction to OOP in Python
Introduction to OOP in Python
Aleksander Fabijan
 
Threading in C#
Threading in C#
Medhat Dawoud
 
Arrays in java
Arrays in java
Arzath Areeff
 
Object Oriented Concept
Object Oriented Concept
D Nayanathara
 
L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdf
BhanuJatinSingh
 
OOP Presentation.pptx
OOP Presentation.pptx
DurgaPrasadVasantati
 

More Related Content

What's hot (20)

Object oriented programming
Object oriented programming
Amit Soni (CTFL)
 
Object Oriented Language
Object Oriented Language
dheva B
 
Oop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
Polymorphism in java
Polymorphism in java
Elizabeth alexander
 
An Introduction to Drupal
An Introduction to Drupal
Tobias Ratschiller
 
object oriented Programming ppt
object oriented Programming ppt
Nitesh Dubey
 
Oops
Oops
Sankar Balasubramanian
 
Object oriented programming interview questions
Object oriented programming interview questions
Keet Sugathadasa
 
Introduction to oop
Introduction to oop
colleges
 
Python-Encapsulation.pptx
Python-Encapsulation.pptx
Karudaiyar Ganapathy
 
OOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptx
Mohamed Essam
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
Glenn Guden
 
Python - object oriented
Python - object oriented
Learnbay Datascience
 
Chapter 07 inheritance
Chapter 07 inheritance
Praveen M Jigajinni
 
OOPS Basics With Example
OOPS Basics With Example
Thooyavan Venkatachalam
 
C# File IO Operations
C# File IO Operations
Prem Kumar Badri
 
Introduction to OOP in Python
Introduction to OOP in Python
Aleksander Fabijan
 
Threading in C#
Threading in C#
Medhat Dawoud
 
Arrays in java
Arrays in java
Arzath Areeff
 
Object Oriented Concept
Object Oriented Concept
D Nayanathara
 

Similar to Object-Oriented Programming (OOP) (20)

L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdf
BhanuJatinSingh
 
OOP Presentation.pptx
OOP Presentation.pptx
DurgaPrasadVasantati
 
OOP Presentation.pptx
OOP Presentation.pptx
DurgaPrasadVasantati
 
1 intro
1 intro
abha48
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
Aida Ramlan II
 
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
akashsachu221
 
Bab satu
Bab satu
Aida Ramlan II
 
babsatu-140703233001-phpapp666666601.pdf
babsatu-140703233001-phpapp666666601.pdf
kashafishfaq21
 
Chapter 04 object oriented programming
Chapter 04 object oriented programming
Praveen M Jigajinni
 
chapterOne.pptxFSdgfqdzwwfagxgghvkjljhcxCZZXvcbx
chapterOne.pptxFSdgfqdzwwfagxgghvkjljhcxCZZXvcbx
berihun18
 
oop.pptx
oop.pptx
KabitaParajuli3
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
General oops concepts
General oops concepts
nidhiyagnik123
 
Lecture 1 oop
Lecture 1 oop
Tony Apreku
 
Object oriented programming 6 oop with c++
Object oriented programming 6 oop with c++
Vaibhav Khanna
 
introduction of Object oriented programming
introduction of Object oriented programming
RiturajJain8
 
Introduction.ppt JAVA SCRIPT PROGRAMMING AND
Introduction.ppt JAVA SCRIPT PROGRAMMING AND
Jifarnecho
 
Object Oriented Programming Concepts
Object Oriented Programming Concepts
Abhigyan Singh Yadav
 
OOP Introduction with java programming language
OOP Introduction with java programming language
Md.Al-imran Roton
 
Computer_Programming_Part_II_Segment_01.pdf
Computer_Programming_Part_II_Segment_01.pdf
et243047
 
L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdf
BhanuJatinSingh
 
1 intro
1 intro
abha48
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
Aida Ramlan II
 
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
akashsachu221
 
babsatu-140703233001-phpapp666666601.pdf
babsatu-140703233001-phpapp666666601.pdf
kashafishfaq21
 
Chapter 04 object oriented programming
Chapter 04 object oriented programming
Praveen M Jigajinni
 
chapterOne.pptxFSdgfqdzwwfagxgghvkjljhcxCZZXvcbx
chapterOne.pptxFSdgfqdzwwfagxgghvkjljhcxCZZXvcbx
berihun18
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
Object oriented programming 6 oop with c++
Object oriented programming 6 oop with c++
Vaibhav Khanna
 
introduction of Object oriented programming
introduction of Object oriented programming
RiturajJain8
 
Introduction.ppt JAVA SCRIPT PROGRAMMING AND
Introduction.ppt JAVA SCRIPT PROGRAMMING AND
Jifarnecho
 
Object Oriented Programming Concepts
Object Oriented Programming Concepts
Abhigyan Singh Yadav
 
OOP Introduction with java programming language
OOP Introduction with java programming language
Md.Al-imran Roton
 
Computer_Programming_Part_II_Segment_01.pdf
Computer_Programming_Part_II_Segment_01.pdf
et243047
 
Ad

More from Ahmad karawash (10)

Introduction to-data-science
Introduction to-data-science
Ahmad karawash
 
How to understand your data
How to understand your data
Ahmad karawash
 
Cloud storage with AWS
Cloud storage with AWS
Ahmad karawash
 
Message queues
Message queues
Ahmad karawash
 
Build a custom metrics on aws cloud
Build a custom metrics on aws cloud
Ahmad karawash
 
Password hashing, salting, bycrpt
Password hashing, salting, bycrpt
Ahmad karawash
 
Brute Force Attack
Brute Force Attack
Ahmad karawash
 
Reasoning of database consistency through description logics
Reasoning of database consistency through description logics
Ahmad karawash
 
Cloud computing and Service model
Cloud computing and Service model
Ahmad karawash
 
From use case to software architecture
From use case to software architecture
Ahmad karawash
 
Introduction to-data-science
Introduction to-data-science
Ahmad karawash
 
How to understand your data
How to understand your data
Ahmad karawash
 
Cloud storage with AWS
Cloud storage with AWS
Ahmad karawash
 
Build a custom metrics on aws cloud
Build a custom metrics on aws cloud
Ahmad karawash
 
Password hashing, salting, bycrpt
Password hashing, salting, bycrpt
Ahmad karawash
 
Reasoning of database consistency through description logics
Reasoning of database consistency through description logics
Ahmad karawash
 
Cloud computing and Service model
Cloud computing and Service model
Ahmad karawash
 
From use case to software architecture
From use case to software architecture
Ahmad karawash
 
Ad

Recently uploaded (20)

Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Software Testing & it’s types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Tech Services
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
Software Testing & it’s types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Tech Services
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 

Object-Oriented Programming (OOP)

  • 2. OUTLINE • Definitions • Classes & Objects • OOP concepts • Pros & Cons 2
  • 4. DEFINITION • OOP is mainly a program design philosophy. • Key idea: The real world can be “accurately” described as a collection of objects that interact. • Everything is grouped as self sustainable "objects". Hence, you gain reusability by means of four main OOP concepts. 4 Object-Oriented Programming (OOP)
  • 5. OOP BASIC TERMINOLOGY • Object - usually a person, place or thing (a noun) • Method - an action performed by an object (a verb) • Property or attribute - Characteristics of certain object. • Class - a category of similar objects (such as automobiles), does not hold any values of the object’ s attributes/properties 5 Object-Oriented Programming (OOP)
  • 6. OPERATIONS/METHODS • In OOP, programmers define not only the data type of a data structure, but also the types of operations/methods (functions) that can be applied to the data structure. • In this way, the data structure becomes an object that includes both data and functions (methods) in one unit. In addition, programmers can create relationships between one object and another. • For example, objects can inherit characteristics from other objects. 6 Object-Oriented Programming (OOP)
  • 7. OOP LANGUAGES • Pure OO Languages • Ruby, Python, Scala, JADE. • Hybrid OO Languages • Delphi, C++, Java, C#, VB.NET, Pascal, Visual Basic, MATLAB, Fortran, Perl, COBOL, PHP. 7 Object-Oriented Programming (OOP)
  • 9. DEFINITIONS • A class is a prototype, idea, and blueprint for creating objects. • For example, in Java we define classes, which in turn are used to create objects • A class has a constructor for creating objects • Class is composed of three things: its name, attributes/properties, and methods. • Each copy of an object from a particular class is called an instance of the class. • The act of creating a new instance of a class is called instantiation. 9 Classes & Objects
  • 10. CLASSES V.S. OBJECTS • A class is a definition of objects with the same properties and the same methods. • An object is an instance of a class 10 Classes & Objects
  • 11. TECHNICAL CONTRAST BETWEEN OBJECTS & CLASSES Object is a class in “runtime” 11 Classes & Objects
  • 12. ALMOST EVERYTHING IN THE WORLD CAN BE REPRESENTED AS AN OBJECT • A flower, a tree, an animal • A student, a professor • A desk, a chair, a classroom, a building, etc. 12 Classes & Objects
  • 13. IN SHORT An Object is a Class when it comes alive! • Homo Sapien is a class, John and Jack are objects • Animal is a class, the cat is an object • Vehicle is a class, my neighbor's BMW is an object • Galaxy is a class, the MilkyWay is an object 13 Classes & Objects
  • 14. OBJECTS NEED TO COLLABORATE! • Objects are useless unless they can collaborate to solve a problem. • Each object is responsible for its own behavior and status. • No one object can carry out every responsibility on its own. 14 Classes & Objects
  • 15. HOW DO OBJECTS INTERACT WITH EACH OTHER? 15 Classes & Objects
  • 16. EXAMPLE OF OBJECT INTERACTION The OrderEntryForm wants Order to calculate the total CAD value for the order. 16 Classes & Objects
  • 18. OOP FOUR MAIN CONCEPTS Encapsulation Inheritance Abstraction Polymorphism 18 OOP Concepts
  • 19. OOP CONCEPTS - ENCAPSULATION 19
  • 20. ENCAPSULATION DEFINITION • Is the inclusion of property & method within a class/object in which it needs to function properly. • Also, enables reusability of an instant of an already implemented class within a new class while hiding & protecting the method and properties from the client classes. 20 OOP concepts - Encapsulation
  • 21. ENCAPSULATION WITH CLASSES • The class is kind of a container or capsule or a cell, which encapsulate the set of methods, attributes and properties to provide its indented functionalities to other classes. • In that sense, encapsulation also allows a class to change its internal implementation without hurting the overall functioning of the system. • That idea of encapsulation is to hide how a class does its operations while allowing requesting its operations. 21 OOP concepts - Encapsulation
  • 22. ENCAPSULATION IN ACTION Example: Let’s say we have a class called “Date” (day, month, year). And then you need to define another class called “Person” that has the following attributes (first name, last name, and birthdate). So in this case we can instantiate an object from class “Date” inside class “Person” 22 OOP concepts - Encapsulation Date Person
  • 23. ENCAPSULATION – BENEFITS • Ensures that structural changes remain local: • Changing the class internals does not affect any code outside of the class • Changing methods' implementation does not reflect the clients using them • Encapsulation allows adding some logic when accessing client's data • E.g. validation on modifying a property value • Hiding implementation details reduces complexity -> easier maintenance 23 OOP concepts - Encapsulation
  • 24. OOP CONCEPTS - INHERITANCE 24
  • 25. INHERITANCE DEFINITION • Term comes from inheritance of traits like eye color, hair color, and so on. • Classes with properties in common can be grouped so that their common properties are only defined once in parent class. • Superclass – inherit its attributes & methods to the subclass(es). • Subclass – can inherit all its superclass attributes & methods besides having its own unique attributes & methods. 25 OOP concepts - Inheritance
  • 26. INHERITANCE PARENT/CHILD • Inheritance allows child classes to inherit the characteristics of existing parent class • Attributes (fields and properties) • Operations (methods) • Child class can extend the parent class • Add new fields and methods • Redefine methods (modify existing behavior) 26 OOP concepts - Inheritance
  • 27. INHERITANCE BENEFITS • Expresses commonality among classes/objects • Allows code reusability • Highlights relationships • Helps in code organization 27 OOP concepts - Inheritance
  • 29. EXAMPLE: SINGLE INHERITANCE One class inherits from another. 29 OOP concepts - Inheritance
  • 30. EXAMPLE: MULTIPLE INHERITANCE A class can inherit from several other classes. Most modern languages don’t support multiple inheritance! 30 OOP concepts - Inheritance
  • 31. OOP CONCEPTS - ABSTRACTION 31
  • 32. ABSTRACTION DEFINITION • Abstraction is a basic representation of a concept. • It is the process of removing characteristics from something in order to reduce it to a set of essential characteristics. • Through the process of abstraction, a programmer hides all but the relevant data about a class in order to reduce complexity and increase reusability. 32 OOP concepts - Abstraction
  • 33. ABSTRACTION BENEFITS • Abstraction allows programmers to represent complex real world in the simplest manner. • It represent the necessary features an object should possess without representing the background details. • It allow ease reusability and understanding for the design and enable extension. 33 OOP concepts - Abstraction
  • 34. ABSTRACT CLASS • An abstract class, which declared with the “abstract” keyword, cannot be instantiated. • It can only be used as a super-class for other classes that extend the abstract class. Abstract class is a design concept and implementation gets completed when it is being realized by a subclass. 34 OOP concepts - Abstraction
  • 35. TYPE OF CLASSES Concrete Class Abstract Class Can be instantiated directly Cannot be instantiated directly 35 OOP concepts - Abstraction
  • 36. ABSTRACTION + INHERITANCE Concrete Class Abstract Class Can be instantiated directly Cannot be instantiated directly Person Teacher Student DOB: Name: Address: Specialization: Academic Title: Etc…: DOB: Name: Address: GPA: Courses: Etc…: DOB Name Address Can be instantiated directly 36 OOP concepts - Abstraction
  • 37. ABSTRACT CLASS: INSTANCE & OPERATION • An abstract class is a class that may not have any direct instances. • An abstract operation is an operation that it is incomplete and requires a child to supply an implementation of the operation. 37 OOP concepts - Abstraction
  • 38. OOP CONCEPTS - POLYMORPHISM 38
  • 39. POLYMORPHISM DEFINITION • Polymorphisms is a generic term that means 'many shapes’. • More precisely Polymorphisms means the ability to request that the same methods be performed by a wide range of different types of things. • It is achieved by using many different techniques named method overloading, operator overloading, and method overriding. 39 OOP concepts - Polymorphism
  • 40. POLYMORPHISM TRAITS • An object has “multiple identities”, based on its class inheritance tree • It can be used in different ways 40 OOP concepts - Polymorphism
  • 41. POLYMORPHISM METHODS • In Java, two or more classes could each have a method called output. • Each output method would do the right thing for the class that it was in. • One output might display a number (output.number) in one class, whereas it might display a name (output.text) in another class. 41 OOP concepts - Polymorphism
  • 42. POLYMORPHISM + ABSTRACT CLASS EXAMPLE Shape method Draw() Circle Circle.Draw() Triangle Triangle.Draw() Square Square.Draw() 42 OOP concepts - Polymorphism
  • 44. OOP PROS • Code reuse & recycling • Improved software-development productivity • Improved software maintainability • Faster development • Lower cost of development • Higher-quality software • Encapsulation 44 Conclusion
  • 45. OOP CONS • Steep learning curve • Could lead to larger program sizes • Could produce slower programs 45 Conclusion