What are the four pillars of OO programming? (Summary)
a. Inheritance
i. (e.g. object triangle inherits from object shape)
b. Abstraction
i. Expose relevant functions and hides irrelevant, abstract complexity, a wrapper, private vs public properties.
c. Polymorphism
i. Many forms, one interface having many behaviours. Invoke base class in a child clase.
d. Encapsulation
i. Methods and functions are encapsulated in a class.
Detailed version:
1. Abstraction
Abstraction is a process of exposing essential features of an entity by hiding the other irrelevant details. Abstraction mainly reduces complexity and increases efficiency. An entity can have multiple abstractions.
2. Encapsulation
Encapsulation is the process of putting data and the operations (functions) that can be performed on that data into a single container called class. Now, any programmer can use this class without knowing how it is implemented. Due to encapsulation, data is insulated, thus not directly accessible from the outside world. This is known as Data Hiding.
Remember, Encapsulation is not data hiding, but, Encapsulation leads to data hiding.
3. Inheritance
In a nutshell, inheritance is a process of creating new class from the existing one. The new class may have some additional properties and functionalitiy.
4. Polymorphism
Poly means many and Morphs means forms. Polymorphism refers to the ability to take multiple forms and it allows us to invoke derived class methods through a base class reference during run-time.
