SlideShare a Scribd company logo
Four Pillars of Object-
Oriented Programming
(OOP)
1. Data Abstraction
Definition: Hides implementation details while exposing
only the essential features of an object.
Benefits: Reduces code complexity and focuses on relevant
functionality.
Example:
JavaScript:
class Car {
#engine; // private field
constructor() {
this.#engine = 'V8';
}
startEngine() {
console.log('Engine started');
Four Pillars of Object-Oriented Programming (OOP) 1
}
getEngine() {
return this.#engine;
}
}
const car = new Car();
console.log(car.getEngine()); // Output: 'V8'
TypeScript:
class Car {
private engine: string = 'V8';
startEngine() {
console.log('Engine started');
}
getEngine() {
return this.engine;
}
}
const car = new Car();
console.log(car.getEngine()); // Output: 'V8'
C++:
class Car {
private:
std::string engine = "V8";
public:
void startEngine() {
std::cout << "Engine started" << std::endl;
}
std::string getEngine() {
Four Pillars of Object-Oriented Programming (OOP) 2
return engine;
}
};
int main() {
Car car;
std::cout << car.getEngine() << std::endl; // Output: "V8"
car.startEngine();
return 0;
}
Python:
class Car:
def __init__(self):
self.__engine = "V8"
def start_engine(self):
print("Engine started")
def get_engine(self):
return self.__engine
car = Car()
print(car.get_engine()) # Output: "V8"
2. Inheritance
Definition: A mechanism where a new class is derived from
an existing class.
Types of Inheritance:
Single Inheritance: One class inherits from another.
Multilevel Inheritance: A class inherits from another
class, which in turn inherits from another.
Multiple Inheritance: A class inherits from multiple
classes (not recommended in some languages).
Four Pillars of Object-Oriented Programming (OOP) 3
Hierarchical Inheritance: Multiple classes inherit from
a single base class.
Hybrid Inheritance: Combination of multiple types of
inheritance.
Examples:
JavaScript:
class Animal {
speak() {
console.log("Animal speaks");
}
}
class Dog extends Animal {
speak() {
console.log("Dog barks");
}
}
const dog = new Dog();
dog.speak(); // Output: "Dog barks"
TypeScript:
class Animal {
speak() {
console.log("Animal speaks");
}
}
class Dog extends Animal {
speak() {
console.log("Dog barks");
}
}
Four Pillars of Object-Oriented Programming (OOP) 4
const dog = new Dog();
dog.speak(); // Output: "Dog barks"
C++:
class Animal {
public:
void speak() {
std::cout << "Animal speaks" << std::endl;
}
};
class Dog : public Animal {
public:
void speak() {
std::cout << "Dog barks" << std::endl;
}
};
int main() {
Dog dog;
dog.speak(); // Output: "Dog barks"
return 0;
}
Python:
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def speak(self):
print("Dog barks")
dog = Dog()
dog.speak() # Output: "Dog barks"
Four Pillars of Object-Oriented Programming (OOP) 5
3. Polymorphism
Definition: The ability for objects to take many forms,
allowing the same method or function to behave differently
based on the object.
Types:
Compile-time Polymorphism: Achieved via method
overloading (function with the same name but different
parameters).
Run-time Polymorphism: Achieved via method overriding
(derived class changes the behavior of a base class
method).
Examples:
JavaScript (Run-time):
class Animal {
speak() {
console.log("Animal speaks");
}
}
class Dog extends Animal {
speak() {
console.log("Dog barks");
}
}
let animal = new Animal();
let dog = new Dog();
animal.speak(); // Output: "Animal speaks"
dog.speak(); // Output: "Dog barks"
TypeScript (Run-time):
class Animal {
speak() {
console.log("Animal speaks");
Four Pillars of Object-Oriented Programming (OOP) 6
}
}
class Dog extends Animal {
speak() {
console.log("Dog barks");
}
}
const animal = new Animal();
const dog = new Dog();
animal.speak(); // Output: "Animal speaks"
dog.speak(); // Output: "Dog barks"
C++ (Run-time):
class Animal {
public:
virtual void speak() {
std::cout << "Animal speaks" << std::endl;
}
};
class Dog : public Animal {
public:
void speak() override {
std::cout << "Dog barks" << std::endl;
}
};
int main() {
Animal* animal = new Animal();
Animal* dog = new Dog();
animal->speak(); // Output: "Animal speaks"
dog->speak(); // Output: "Dog barks"
delete animal;
delete dog;
Four Pillars of Object-Oriented Programming (OOP) 7
return 0;
}
Python (Run-time):
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def speak(self):
print("Dog barks")
animal = Animal()
dog = Dog()
animal.speak() # Output: "Animal speaks"
dog.speak() # Output: "Dog barks"
4. Encapsulation
Definition: The practice of bundling data and methods that
operate on that data within a single unit (class), and
restricting access to some of the object’s components.
Example:
JavaScript:
class Account {
#balance = 0; // private field
deposit(amount) {
this.#balance += amount;
}
getBalance() {
return this.#balance;
}
}
Four Pillars of Object-Oriented Programming (OOP) 8
const account = new Account();
account.deposit(100);
console.log(account.getBalance()); // Output: 100
TypeScript:
class Account {
private balance: number = 0;
deposit(amount: number) {
this.balance += amount;
}
getBalance() {
return this.balance;
}
}
const account = new Account();
account.deposit(100);
console.log(account.getBalance()); // Output: 100
C++:
class Account {
private:
double balance = 0.0;
public:
void deposit(double amount) {
balance += amount;
}
double getBalance() {
return balance;
}
};
Four Pillars of Object-Oriented Programming (OOP) 9
int main() {
Account account;
account.deposit(100);
std::cout << account.getBalance() << std::endl; // Output: 100
return 0;
}
Python:
class Account:
def __init__(self):
self.__balance = 0
def deposit(self, amount):
self.__balance += amount
def get_balance(self):
return self.__balance
account = Account()
account.deposit(100)
print(account.get_balance()) # Output: 100
Access Specifiers (C++)
Public: Accessible from outside the class.
Private: Not accessible from outside the class.
Protected: Accessible in the class and its derived classes.
Virtual Functions (C++)
Definition: Virtual functions enable runtime polymorphism.
A virtual function in a base class can be overridden by a
derived class to provide custom behavior.
Example:
Four Pillars of Object-Oriented Programming (OOP) 10
class Animal {
public:
virtual void speak() {
std::cout << "Animal speaks" << std::endl;
}
};
class Dog : public Animal {
public:
void speak() override {
std::cout << "Dog barks" << std::endl;
}
};
Pure Object-Oriented Programming Languages
Smalltalk
Eiffel
Self
Operator Overloading
Definition: Allows custom behavior for operators (e.g., +,
-, *, etc.) with user-defined data types.
Example (C++):
class Complex {
public:
int real, imag;
Complex operator + (const Complex& c) {
Complex temp;
temp.real = real + c.real;
temp.imag = imag + c.imag;
return temp;
}
};
Four Pillars of Object-Oriented Programming (OOP) 11
Summary of Object-Oriented Programming (OOP)
Concepts
Concept Definition Examples
Data
Abstraction
Hides implementation
details and exposes
only essential
features.
JavaScript: #engine field in
Car class. TypeScript:
private engine in Car class.
C++: private engine in Car
class. Python: __engine in
Car class.
Inheritance
Deriving a new class
from an existing class
for reusability.
Single, Multi-level,
Multiple, Hierarchical,
Hybrid inheritance. Example:
Dog inherits Animal .
Polymorphism
The ability for objects
to take many forms.
Run-time: Methods can be
overridden. JavaScript: Dog
class overrides speak() from
Animal class.
Encapsulation
Bundling data and
methods, restricting
access to certain
components.
JavaScript: #balance in
Account . TypeScript: private
balance in Account . C++:
private balance in Account .
Python: __balance in Account .
Access
Specifiers
(C++)
Defines the access
level for class
members.
Public: Accessible outside
class. Private: Not
accessible outside class.
Protected: Accessible in
derived classes.
Virtual
Functions
(C++)
Enables run-time
polymorphism, allowing
derived classes to
override base class
functions.
virtual void speak() in Animal
class; overridden in Dog
class.
Pure OOP
Languages
Languages that strictly
follow OOP principles.
Smalltalk, Eiffel, Self
Four Pillars of Object-Oriented Programming (OOP) 12
Operator
Overloading
Allows operators (e.g.,
+ , - ) to be redefined
for user-defined types.
C++: operator + for Complex
class to add two complex
numbers.
Types of
Constructors
Special methods for
object initialization.
Default Constructor: No
arguments. Parameterized
Constructor: Initializes
with specific values. Copy
Constructor: Copies state
from another object.
Polymorphism
Types
Compile-time: Achieved
through overloading.
Run-time: Achieved
through overriding.
Compile-time: Method
overloading. Run-time:
Method overriding.
Four Pillars of Object-Oriented Programming (OOP) 13
Ad

More Related Content

Similar to Mastering OOP: Understanding the Four Core Pillars (20)

Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
Stefano Fago
 
Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 1Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 1
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
intelliyole
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
Piyush Katariya
 
Cocoa for Web Developers
Cocoa for Web DevelopersCocoa for Web Developers
Cocoa for Web Developers
georgebrock
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
Garth Gilmour
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
Microsoft Developer Network (MSDN) - Belgium and Luxembourg
 
ECMAScript 2015
ECMAScript 2015ECMAScript 2015
ECMAScript 2015
Sebastian Pederiva
 
Wien15 java8
Wien15 java8Wien15 java8
Wien15 java8
Jaanus Pöial
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
Ayesha Bhatti
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
Venkateswaran Kandasamy
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
Abhijeet Dubey
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
arjun431527
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
aptechsravan
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - Warburton
Codemotion
 
C++ theory
C++ theoryC++ theory
C++ theory
Shyam Khant
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
Stefano Fago
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
intelliyole
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
Piyush Katariya
 
Cocoa for Web Developers
Cocoa for Web DevelopersCocoa for Web Developers
Cocoa for Web Developers
georgebrock
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
Garth Gilmour
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
arjun431527
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - Warburton
Codemotion
 

More from Marcel David (20)

Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
 
Computer Crime: An Exploration of Cybersecurity Threats and Solutions
Computer Crime: An Exploration of Cybersecurity Threats and SolutionsComputer Crime: An Exploration of Cybersecurity Threats and Solutions
Computer Crime: An Exploration of Cybersecurity Threats and Solutions
Marcel David
 
Beef: Nutritional Value, Processing, and Its Role in Food Engineering
Beef: Nutritional Value, Processing, and Its Role in Food EngineeringBeef: Nutritional Value, Processing, and Its Role in Food Engineering
Beef: Nutritional Value, Processing, and Its Role in Food Engineering
Marcel David
 
Chemotherapy: Mechanism, Applications, and Side Effects
Chemotherapy: Mechanism, Applications, and Side EffectsChemotherapy: Mechanism, Applications, and Side Effects
Chemotherapy: Mechanism, Applications, and Side Effects
Marcel David
 
Algorithms for Rendering Depth of Field Effects in Computer Graphics
Algorithms for Rendering Depth of Field Effects in Computer GraphicsAlgorithms for Rendering Depth of Field Effects in Computer Graphics
Algorithms for Rendering Depth of Field Effects in Computer Graphics
Marcel David
 
Recognizing Handwritten Bangla Text Using Explainable AI: Techniques & Applic...
Recognizing Handwritten Bangla Text Using Explainable AI: Techniques & Applic...Recognizing Handwritten Bangla Text Using Explainable AI: Techniques & Applic...
Recognizing Handwritten Bangla Text Using Explainable AI: Techniques & Applic...
Marcel David
 
Machine Learning Approach to Detect Brain Tumors: Techniques and Applications
Machine Learning Approach to Detect Brain Tumors: Techniques and ApplicationsMachine Learning Approach to Detect Brain Tumors: Techniques and Applications
Machine Learning Approach to Detect Brain Tumors: Techniques and Applications
Marcel David
 
Japan International Cooperation Agency (JICA) and Its Impact on the Nursing S...
Japan International Cooperation Agency (JICA) and Its Impact on the Nursing S...Japan International Cooperation Agency (JICA) and Its Impact on the Nursing S...
Japan International Cooperation Agency (JICA) and Its Impact on the Nursing S...
Marcel David
 
Train to Pakistan: Summary, Themes, and Analysis
Train to Pakistan: Summary, Themes, and AnalysisTrain to Pakistan: Summary, Themes, and Analysis
Train to Pakistan: Summary, Themes, and Analysis
Marcel David
 
Gothic Architecture: History, Features, and Influences
Gothic Architecture: History, Features, and InfluencesGothic Architecture: History, Features, and Influences
Gothic Architecture: History, Features, and Influences
Marcel David
 
Tree Data Structure: Concepts, Types, and Algorithms
Tree Data Structure: Concepts, Types, and AlgorithmsTree Data Structure: Concepts, Types, and Algorithms
Tree Data Structure: Concepts, Types, and Algorithms
Marcel David
 
Exploring Tangail: Porabari Sweets, 201 Gombuj Mosque & Tangail Saree
Exploring Tangail: Porabari Sweets, 201 Gombuj Mosque & Tangail SareeExploring Tangail: Porabari Sweets, 201 Gombuj Mosque & Tangail Saree
Exploring Tangail: Porabari Sweets, 201 Gombuj Mosque & Tangail Saree
Marcel David
 
Introduction to Binary Search Trees (BST): Concepts, Implementation, and Appl...
Introduction to Binary Search Trees (BST): Concepts, Implementation, and Appl...Introduction to Binary Search Trees (BST): Concepts, Implementation, and Appl...
Introduction to Binary Search Trees (BST): Concepts, Implementation, and Appl...
Marcel David
 
Types of Graphs in Computer Engineering: Visualization for Data and Algorithms
Types of Graphs in Computer Engineering: Visualization for Data and AlgorithmsTypes of Graphs in Computer Engineering: Visualization for Data and Algorithms
Types of Graphs in Computer Engineering: Visualization for Data and Algorithms
Marcel David
 
QuickBooks Accounting Software: Streamlining Financial Management
QuickBooks Accounting Software: Streamlining Financial ManagementQuickBooks Accounting Software: Streamlining Financial Management
QuickBooks Accounting Software: Streamlining Financial Management
Marcel David
 
6LoWPAN: Enabling IPv6 for Low-Power Wireless Networks
6LoWPAN: Enabling IPv6 for Low-Power Wireless Networks6LoWPAN: Enabling IPv6 for Low-Power Wireless Networks
6LoWPAN: Enabling IPv6 for Low-Power Wireless Networks
Marcel David
 
WiMAX: Wireless Broadband Technology for High-Speed Connectivity
WiMAX: Wireless Broadband Technology for High-Speed ConnectivityWiMAX: Wireless Broadband Technology for High-Speed Connectivity
WiMAX: Wireless Broadband Technology for High-Speed Connectivity
Marcel David
 
Long Term Evolution (LTE): High-Speed Wireless Communication Explained
Long Term Evolution (LTE): High-Speed Wireless Communication ExplainedLong Term Evolution (LTE): High-Speed Wireless Communication Explained
Long Term Evolution (LTE): High-Speed Wireless Communication Explained
Marcel David
 
Understanding Probability: Fundamentals, Applications, and Real-World Examples
Understanding Probability: Fundamentals, Applications, and Real-World ExamplesUnderstanding Probability: Fundamentals, Applications, and Real-World Examples
Understanding Probability: Fundamentals, Applications, and Real-World Examples
Marcel David
 
Understanding Median in Mathematics: A Key Measure of Central Tendency
Understanding Median in Mathematics: A Key Measure of Central TendencyUnderstanding Median in Mathematics: A Key Measure of Central Tendency
Understanding Median in Mathematics: A Key Measure of Central Tendency
Marcel David
 
Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
 
Computer Crime: An Exploration of Cybersecurity Threats and Solutions
Computer Crime: An Exploration of Cybersecurity Threats and SolutionsComputer Crime: An Exploration of Cybersecurity Threats and Solutions
Computer Crime: An Exploration of Cybersecurity Threats and Solutions
Marcel David
 
Beef: Nutritional Value, Processing, and Its Role in Food Engineering
Beef: Nutritional Value, Processing, and Its Role in Food EngineeringBeef: Nutritional Value, Processing, and Its Role in Food Engineering
Beef: Nutritional Value, Processing, and Its Role in Food Engineering
Marcel David
 
Chemotherapy: Mechanism, Applications, and Side Effects
Chemotherapy: Mechanism, Applications, and Side EffectsChemotherapy: Mechanism, Applications, and Side Effects
Chemotherapy: Mechanism, Applications, and Side Effects
Marcel David
 
Algorithms for Rendering Depth of Field Effects in Computer Graphics
Algorithms for Rendering Depth of Field Effects in Computer GraphicsAlgorithms for Rendering Depth of Field Effects in Computer Graphics
Algorithms for Rendering Depth of Field Effects in Computer Graphics
Marcel David
 
Recognizing Handwritten Bangla Text Using Explainable AI: Techniques & Applic...
Recognizing Handwritten Bangla Text Using Explainable AI: Techniques & Applic...Recognizing Handwritten Bangla Text Using Explainable AI: Techniques & Applic...
Recognizing Handwritten Bangla Text Using Explainable AI: Techniques & Applic...
Marcel David
 
Machine Learning Approach to Detect Brain Tumors: Techniques and Applications
Machine Learning Approach to Detect Brain Tumors: Techniques and ApplicationsMachine Learning Approach to Detect Brain Tumors: Techniques and Applications
Machine Learning Approach to Detect Brain Tumors: Techniques and Applications
Marcel David
 
Japan International Cooperation Agency (JICA) and Its Impact on the Nursing S...
Japan International Cooperation Agency (JICA) and Its Impact on the Nursing S...Japan International Cooperation Agency (JICA) and Its Impact on the Nursing S...
Japan International Cooperation Agency (JICA) and Its Impact on the Nursing S...
Marcel David
 
Train to Pakistan: Summary, Themes, and Analysis
Train to Pakistan: Summary, Themes, and AnalysisTrain to Pakistan: Summary, Themes, and Analysis
Train to Pakistan: Summary, Themes, and Analysis
Marcel David
 
Gothic Architecture: History, Features, and Influences
Gothic Architecture: History, Features, and InfluencesGothic Architecture: History, Features, and Influences
Gothic Architecture: History, Features, and Influences
Marcel David
 
Tree Data Structure: Concepts, Types, and Algorithms
Tree Data Structure: Concepts, Types, and AlgorithmsTree Data Structure: Concepts, Types, and Algorithms
Tree Data Structure: Concepts, Types, and Algorithms
Marcel David
 
Exploring Tangail: Porabari Sweets, 201 Gombuj Mosque & Tangail Saree
Exploring Tangail: Porabari Sweets, 201 Gombuj Mosque & Tangail SareeExploring Tangail: Porabari Sweets, 201 Gombuj Mosque & Tangail Saree
Exploring Tangail: Porabari Sweets, 201 Gombuj Mosque & Tangail Saree
Marcel David
 
Introduction to Binary Search Trees (BST): Concepts, Implementation, and Appl...
Introduction to Binary Search Trees (BST): Concepts, Implementation, and Appl...Introduction to Binary Search Trees (BST): Concepts, Implementation, and Appl...
Introduction to Binary Search Trees (BST): Concepts, Implementation, and Appl...
Marcel David
 
Types of Graphs in Computer Engineering: Visualization for Data and Algorithms
Types of Graphs in Computer Engineering: Visualization for Data and AlgorithmsTypes of Graphs in Computer Engineering: Visualization for Data and Algorithms
Types of Graphs in Computer Engineering: Visualization for Data and Algorithms
Marcel David
 
QuickBooks Accounting Software: Streamlining Financial Management
QuickBooks Accounting Software: Streamlining Financial ManagementQuickBooks Accounting Software: Streamlining Financial Management
QuickBooks Accounting Software: Streamlining Financial Management
Marcel David
 
6LoWPAN: Enabling IPv6 for Low-Power Wireless Networks
6LoWPAN: Enabling IPv6 for Low-Power Wireless Networks6LoWPAN: Enabling IPv6 for Low-Power Wireless Networks
6LoWPAN: Enabling IPv6 for Low-Power Wireless Networks
Marcel David
 
WiMAX: Wireless Broadband Technology for High-Speed Connectivity
WiMAX: Wireless Broadband Technology for High-Speed ConnectivityWiMAX: Wireless Broadband Technology for High-Speed Connectivity
WiMAX: Wireless Broadband Technology for High-Speed Connectivity
Marcel David
 
Long Term Evolution (LTE): High-Speed Wireless Communication Explained
Long Term Evolution (LTE): High-Speed Wireless Communication ExplainedLong Term Evolution (LTE): High-Speed Wireless Communication Explained
Long Term Evolution (LTE): High-Speed Wireless Communication Explained
Marcel David
 
Understanding Probability: Fundamentals, Applications, and Real-World Examples
Understanding Probability: Fundamentals, Applications, and Real-World ExamplesUnderstanding Probability: Fundamentals, Applications, and Real-World Examples
Understanding Probability: Fundamentals, Applications, and Real-World Examples
Marcel David
 
Understanding Median in Mathematics: A Key Measure of Central Tendency
Understanding Median in Mathematics: A Key Measure of Central TendencyUnderstanding Median in Mathematics: A Key Measure of Central Tendency
Understanding Median in Mathematics: A Key Measure of Central Tendency
Marcel David
 
Ad

Recently uploaded (20)

Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025
Web Designer
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025
Web Designer
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Ad

Mastering OOP: Understanding the Four Core Pillars

  • 1. Four Pillars of Object- Oriented Programming (OOP) 1. Data Abstraction Definition: Hides implementation details while exposing only the essential features of an object. Benefits: Reduces code complexity and focuses on relevant functionality. Example: JavaScript: class Car { #engine; // private field constructor() { this.#engine = 'V8'; } startEngine() { console.log('Engine started'); Four Pillars of Object-Oriented Programming (OOP) 1
  • 2. } getEngine() { return this.#engine; } } const car = new Car(); console.log(car.getEngine()); // Output: 'V8' TypeScript: class Car { private engine: string = 'V8'; startEngine() { console.log('Engine started'); } getEngine() { return this.engine; } } const car = new Car(); console.log(car.getEngine()); // Output: 'V8' C++: class Car { private: std::string engine = "V8"; public: void startEngine() { std::cout << "Engine started" << std::endl; } std::string getEngine() { Four Pillars of Object-Oriented Programming (OOP) 2
  • 3. return engine; } }; int main() { Car car; std::cout << car.getEngine() << std::endl; // Output: "V8" car.startEngine(); return 0; } Python: class Car: def __init__(self): self.__engine = "V8" def start_engine(self): print("Engine started") def get_engine(self): return self.__engine car = Car() print(car.get_engine()) # Output: "V8" 2. Inheritance Definition: A mechanism where a new class is derived from an existing class. Types of Inheritance: Single Inheritance: One class inherits from another. Multilevel Inheritance: A class inherits from another class, which in turn inherits from another. Multiple Inheritance: A class inherits from multiple classes (not recommended in some languages). Four Pillars of Object-Oriented Programming (OOP) 3
  • 4. Hierarchical Inheritance: Multiple classes inherit from a single base class. Hybrid Inheritance: Combination of multiple types of inheritance. Examples: JavaScript: class Animal { speak() { console.log("Animal speaks"); } } class Dog extends Animal { speak() { console.log("Dog barks"); } } const dog = new Dog(); dog.speak(); // Output: "Dog barks" TypeScript: class Animal { speak() { console.log("Animal speaks"); } } class Dog extends Animal { speak() { console.log("Dog barks"); } } Four Pillars of Object-Oriented Programming (OOP) 4
  • 5. const dog = new Dog(); dog.speak(); // Output: "Dog barks" C++: class Animal { public: void speak() { std::cout << "Animal speaks" << std::endl; } }; class Dog : public Animal { public: void speak() { std::cout << "Dog barks" << std::endl; } }; int main() { Dog dog; dog.speak(); // Output: "Dog barks" return 0; } Python: class Animal: def speak(self): print("Animal speaks") class Dog(Animal): def speak(self): print("Dog barks") dog = Dog() dog.speak() # Output: "Dog barks" Four Pillars of Object-Oriented Programming (OOP) 5
  • 6. 3. Polymorphism Definition: The ability for objects to take many forms, allowing the same method or function to behave differently based on the object. Types: Compile-time Polymorphism: Achieved via method overloading (function with the same name but different parameters). Run-time Polymorphism: Achieved via method overriding (derived class changes the behavior of a base class method). Examples: JavaScript (Run-time): class Animal { speak() { console.log("Animal speaks"); } } class Dog extends Animal { speak() { console.log("Dog barks"); } } let animal = new Animal(); let dog = new Dog(); animal.speak(); // Output: "Animal speaks" dog.speak(); // Output: "Dog barks" TypeScript (Run-time): class Animal { speak() { console.log("Animal speaks"); Four Pillars of Object-Oriented Programming (OOP) 6
  • 7. } } class Dog extends Animal { speak() { console.log("Dog barks"); } } const animal = new Animal(); const dog = new Dog(); animal.speak(); // Output: "Animal speaks" dog.speak(); // Output: "Dog barks" C++ (Run-time): class Animal { public: virtual void speak() { std::cout << "Animal speaks" << std::endl; } }; class Dog : public Animal { public: void speak() override { std::cout << "Dog barks" << std::endl; } }; int main() { Animal* animal = new Animal(); Animal* dog = new Dog(); animal->speak(); // Output: "Animal speaks" dog->speak(); // Output: "Dog barks" delete animal; delete dog; Four Pillars of Object-Oriented Programming (OOP) 7
  • 8. return 0; } Python (Run-time): class Animal: def speak(self): print("Animal speaks") class Dog(Animal): def speak(self): print("Dog barks") animal = Animal() dog = Dog() animal.speak() # Output: "Animal speaks" dog.speak() # Output: "Dog barks" 4. Encapsulation Definition: The practice of bundling data and methods that operate on that data within a single unit (class), and restricting access to some of the object’s components. Example: JavaScript: class Account { #balance = 0; // private field deposit(amount) { this.#balance += amount; } getBalance() { return this.#balance; } } Four Pillars of Object-Oriented Programming (OOP) 8
  • 9. const account = new Account(); account.deposit(100); console.log(account.getBalance()); // Output: 100 TypeScript: class Account { private balance: number = 0; deposit(amount: number) { this.balance += amount; } getBalance() { return this.balance; } } const account = new Account(); account.deposit(100); console.log(account.getBalance()); // Output: 100 C++: class Account { private: double balance = 0.0; public: void deposit(double amount) { balance += amount; } double getBalance() { return balance; } }; Four Pillars of Object-Oriented Programming (OOP) 9
  • 10. int main() { Account account; account.deposit(100); std::cout << account.getBalance() << std::endl; // Output: 100 return 0; } Python: class Account: def __init__(self): self.__balance = 0 def deposit(self, amount): self.__balance += amount def get_balance(self): return self.__balance account = Account() account.deposit(100) print(account.get_balance()) # Output: 100 Access Specifiers (C++) Public: Accessible from outside the class. Private: Not accessible from outside the class. Protected: Accessible in the class and its derived classes. Virtual Functions (C++) Definition: Virtual functions enable runtime polymorphism. A virtual function in a base class can be overridden by a derived class to provide custom behavior. Example: Four Pillars of Object-Oriented Programming (OOP) 10
  • 11. class Animal { public: virtual void speak() { std::cout << "Animal speaks" << std::endl; } }; class Dog : public Animal { public: void speak() override { std::cout << "Dog barks" << std::endl; } }; Pure Object-Oriented Programming Languages Smalltalk Eiffel Self Operator Overloading Definition: Allows custom behavior for operators (e.g., +, -, *, etc.) with user-defined data types. Example (C++): class Complex { public: int real, imag; Complex operator + (const Complex& c) { Complex temp; temp.real = real + c.real; temp.imag = imag + c.imag; return temp; } }; Four Pillars of Object-Oriented Programming (OOP) 11
  • 12. Summary of Object-Oriented Programming (OOP) Concepts Concept Definition Examples Data Abstraction Hides implementation details and exposes only essential features. JavaScript: #engine field in Car class. TypeScript: private engine in Car class. C++: private engine in Car class. Python: __engine in Car class. Inheritance Deriving a new class from an existing class for reusability. Single, Multi-level, Multiple, Hierarchical, Hybrid inheritance. Example: Dog inherits Animal . Polymorphism The ability for objects to take many forms. Run-time: Methods can be overridden. JavaScript: Dog class overrides speak() from Animal class. Encapsulation Bundling data and methods, restricting access to certain components. JavaScript: #balance in Account . TypeScript: private balance in Account . C++: private balance in Account . Python: __balance in Account . Access Specifiers (C++) Defines the access level for class members. Public: Accessible outside class. Private: Not accessible outside class. Protected: Accessible in derived classes. Virtual Functions (C++) Enables run-time polymorphism, allowing derived classes to override base class functions. virtual void speak() in Animal class; overridden in Dog class. Pure OOP Languages Languages that strictly follow OOP principles. Smalltalk, Eiffel, Self Four Pillars of Object-Oriented Programming (OOP) 12
  • 13. Operator Overloading Allows operators (e.g., + , - ) to be redefined for user-defined types. C++: operator + for Complex class to add two complex numbers. Types of Constructors Special methods for object initialization. Default Constructor: No arguments. Parameterized Constructor: Initializes with specific values. Copy Constructor: Copies state from another object. Polymorphism Types Compile-time: Achieved through overloading. Run-time: Achieved through overriding. Compile-time: Method overloading. Run-time: Method overriding. Four Pillars of Object-Oriented Programming (OOP) 13
  翻译: