2. What is OOP & 4-pillar?
❏ Object-oriented programming
(OOP) is a programming language
model in which programs are
organized around data, or objects,
rather than functions and logic.
https://htree.plus/
Encapsulation
Inheritance
Polymorphism AbstractionOOP
(4-pillar)
3. https://htree.plus/
Inheritance
❏ Concepts at higher levels are more general.
❏ Concepts at lower levels are more specific (inherit properties of
concepts at higher levels)
Vehicle
Wheeled Vehicle Boat
Car Bicycle
4. Inheritance
(By Programming)
https://htree.plus/
❏ The language mechanism by which one class acquires the
properties (data and operations) of another class
❏ Base Class (or superclass): the class being inherited from
❏ Derived Class (or subclass): the class that inherits
5. https://htree.plus/
❏ You can reuse the methods and data of the existing class
❏ You can extend the existing class by adding new data and new
methods
❏ You can modify the existing class by overloading its methods
with your own implementations
Advantages Of Inheritance
6. https://htree.plus/
Abstraction
❏ Objects in an OOP language provide an abstraction that hides
the internal implementation details.
❏ Abstraction refers to the concept of hiding the complexities of
a system from the users of that system
7. Abstraction
(Real World Example)
● For example, the coffee machine in your kitchen, you just
need to know which methods of the object are available to
call and which input parameters are needed to trigger a
specific operation. But you don’t need to understand how
this method is implemented and which kinds of actions it
has to perform to create the expected result.
8. Abstraction
(By Programming)
using namespace std;
class implementAbstraction
{
private:
int a, b;
public:
// method to set values of
// private members
void set(int x, int y)
{
a = x;
b = y;
}
void display()
{
cout<<"a = " <<a << endl;
cout<<"b = " << b << endl;
}
};
int main()
{
implementAbstraction obj;
obj.set(10, 20);
obj.display();
return 0;
}
10. https://htree.plus/
Encapsulation
(Example)
❏ using System;
❏ namespace OPPs {
❏ class Encapsulation {
❏ private string Name = "Alex";
❏ public string EmployeeName { // Property
❏ get {
❏ return Name;
❏ }
❏ set {
❏ Name = value;
❏ }
❏ }
❏ static void Main(string[] args) {
❏ string Name2 = string.Empty;
❏ // use properties
❏ Encapsulation e = new Encapsulation();
❏ Name2 = e.EmployeeName;
❏ Console.WriteLine("Employee Name: " + Name2);
❏ Console.ReadLine();
❏ }
❏ }
❏ }
11. https://htree.plus/
Advantages Of
Encapsulation & Abstraction
❏ Encapsulation helps us in binding the data(instance
variables) and the member functions(that work on the
instance variables) of a class.
❏ Abstraction helps the user to avoid writing the low level code
❏ Abstraction avoids code duplication and increases
reusability.
❏ Abstraction can change internal implementation of class
independently without affecting the user.
13. https://htree.plus/
Polymorphism
(By Programming)
❏ Two types of polymorphism :
- Dynamic Polymorphism
- Static Polymorphism
❏ The process of binding the overloaded method within object at
compile time is known as Static polymorphism
❏ In dynamic polymorphism method of the program binds with
an object at runtime
15. https://htree.plus/
Advantages Of Polymorphism
❏ It helps programmers reuse the code and classes once written,
tested and implemented. They can be reused in many ways.
❏ Single variable name can be used to store variables of multiple
data types(Float, double, Long, Int etc).
❏ Polymorphism helps in reducing the coupling between
different functionalities.