I like pies, everyone likes pies.
Here’s a photo of some pies:
But this post is not about pies, it’s about A PIE.
A PIE is an easy way to remember the 4 more important concepts of OOP.
Abstraction means that in object oriented programming we need to abstract real world objects intro a simple concept, considering only the more essential behaviours and attributes to define that object in a general way.
This term refers to the fact that in Object Oriented Programming we can have the same Interface for different Objects. For instance, the plus sign, when used with number, we add these two number, and when used with strings it concatenates these two strings.
This means that a class can inherit methods, attributes and fields from another class, and with this you are able to describe a general concept, like mammal animals, they share common characteristics, and then you can create a human class, that inherits from the mammal class, so that it is able to produce milk, but then you can add more specific behaviours to that class, like talking and stuff.
The idea behind encapsulation is to be able to think about objects as a black box, in which you don’t care how it works, but you care about what it does. Imagine you are using objects and you decide to change the inner behaviour of the object, if there were not encapsulation you would have to do changes wherever you used that objects, but with the encapsulation you can change the behaviour, not affecting anything outside the class of these objects.