If you're a programmer you probably heard of 4 pillars of OOP which are Abstraction, Encapsulation, Inheritance, and Polymorphism. You probably don't know yet or forgot the meaning of each pillar. So we probably start describing each pillar so that if one of your friend ask you what is this all about, you can answer them.
1. Abstraction
Abstraction is a process of only showing the relevant or essential feature of your code while hiding other irrelevant detail. For example you have a medical form, school form, or a registration form, what are the similar things on those three? First name, middle name, last name, or age, right? You will only show the essential things for your code, on other word the general.
2. Encapsulation
Think about a real capsule with a chemical inside of it. Encapsulation is just like this, you will hide those functions and data with one unit and just represent it as a single unit. Encapsulation is like related to Data Hiding, but more likely Encapsulation is when you hide your functions or internal data to other modules, is also the way of restricting your module from other modules. Then the child class will also have an additional properties or methods.
Overall, Encapsulation is not all about data hiding, but Encapsulation leads to data hiding.
3. Inheritance
You probably familiar with Inheritance or Inherit word, yes this is like a real world example when someone died and their children inherit the fortune of their parents. But in OOP, no one will die, its just like that the Child class will inherit the properties or methods of its Parent class.
This is the way you can create a new class base on an existing class. So no need to repeat anything that is in the base class.
4. Polymorphism
If you search about Polymorphism (Biology) it is refer to the ability to take into different forms and stages. Polymorphism allows you to put an override methods in the derived class through base class or parent class, it happens during runtime. It means that you can override the methods of the parent class and do other functionality on it.
So a Child class can have different behavior with same name or signature of its Parent class.
This is only a background related to the 4 pillars of OOP, there is a more detailed explanation in the web related on this topic. If you any comments or suggestions feel free to write down below.
1. Abstraction
Abstraction is a process of only showing the relevant or essential feature of your code while hiding other irrelevant detail. For example you have a medical form, school form, or a registration form, what are the similar things on those three? First name, middle name, last name, or age, right? You will only show the essential things for your code, on other word the general.
2. Encapsulation
Think about a real capsule with a chemical inside of it. Encapsulation is just like this, you will hide those functions and data with one unit and just represent it as a single unit. Encapsulation is like related to Data Hiding, but more likely Encapsulation is when you hide your functions or internal data to other modules, is also the way of restricting your module from other modules. Then the child class will also have an additional properties or methods.
Overall, Encapsulation is not all about data hiding, but Encapsulation leads to data hiding.
3. Inheritance
You probably familiar with Inheritance or Inherit word, yes this is like a real world example when someone died and their children inherit the fortune of their parents. But in OOP, no one will die, its just like that the Child class will inherit the properties or methods of its Parent class.
This is the way you can create a new class base on an existing class. So no need to repeat anything that is in the base class.
4. Polymorphism
If you search about Polymorphism (Biology) it is refer to the ability to take into different forms and stages. Polymorphism allows you to put an override methods in the derived class through base class or parent class, it happens during runtime. It means that you can override the methods of the parent class and do other functionality on it.
So a Child class can have different behavior with same name or signature of its Parent class.
This is only a background related to the 4 pillars of OOP, there is a more detailed explanation in the web related on this topic. If you any comments or suggestions feel free to write down below.
Comments
Post a Comment