The Objects Oriented Programming (OOP) is constructed over four major principles: ADT, Encapsulation, Inheritance and Polymorphism. This article will detail each of them.
Objects Oriented Programming is based on 4 principles that if you do not make sure to use properly during your design and implementation, your program will not be a fully, well written, OOP program, and will suffer from a lot of problems. Therefore, it is important to fully understand each of those principles.
1. Abstract Data Type (ADT)
Abstract data type (ADT) is actually the creation of a new type in the language. This type is abstractive, meaning it doesnot represent a specific existing object in the world, but rather a category of objects that exist in the world.
When we think about it every noun in the language is a category. When we say "a cat", we are not referring to a specific cat, but to the category that contains all the cats in the world, and describe them. So when I say "a cat" most people have a general idea of what I mean, what information they will have about each individual object that will be in this category and what kind of action it could do. The same apply to ADTs.
Encapsulation is the strong idea of encapsulating everything into one "close black box". It is the idea that the user will get a black box that he knows what he can do with it, but not how it is working.
If done correctly this principle will allow us to completely change our implementation in the future without harming anyone that use our code. Since encapsulation makes sure that the user's only dependency is in our interface not out inner implementation.
Inheritance is the idea of creating"sub-categories" while using an already existing category (ADT) and only adding what needed to be added.
In inheritance we create a new class which is a sub-type of an existing class. While using the inheritance mechanism we gain: reuse of code, prevention of new bugs, reducing code size, adding to code readability, and most importantly: creating the new class in a way that makes it known as a type that only extend the previous class (or an "Is-A" relationship).
Polymorphism is the idea of using identical interfaces with different implementations. The idea is that by using inheritance plus some other polymorphism tools we create a "family" of entitles that share a common interface. Yet each entitle implement this interface according to its desire and needs.
Once all those entitles share the same interface they can be activate from the same general code that works with a pointer to the interface and we will not care with which one of the entitles we actually work. This allows us to write general code easily and also it allows to easily extend the system to contain more entitles that works with the same interface without needing to change the system itself.
You might also be interested in the following article: