top of page
Search
Writer's picturelaijustine

4 Basic Concept of Object Oriented Programming

Updated: May 22, 2020

There are four pillars of object oriented programming.The four principles are Encapsulation, Data Abstraction, Polymorphism, and Inheritance.


Encapsulation

First of all, encapsulation will be accomplished when objects remain their state in private in a class. Others cannot evaluate directly to this state that they only can call out public function called methods. no class can be assessed unless you are granted. You can used the provided ways to connect with the object.

For example, we encapsulate ‘dog’ logic into a dog class. We cannot change the mood of the dog although we play with it. How hungry the dog is, the mood of the dog and the energy of the dog is the private variables of the ‘state’ of the dog. And when the dog bark, it is its private method. We would not know when will the dog bark.

All we could do is to define the public methods such as play with it, feed it, and let the dog sleep. These behaviors may cause the dog bark. This is the relationship between the public methods and private and this is encapsulation.


Abstraction

Secondly, abstraction, it is the addition of encapsulation. Programs are large usually in object oriented programming design. It is hard to maintain huge codebase. Abstraction can help each object only expose a high level mechanism if using. It will only disclose operation for other objects.

For example, our smart phone. There are only a few buttons on it and many additional details are hidden. We do not have to know how the phone work. All we have to know is how we used it. Maybe the structure inside the phone is multiplex, but the way we use then is simple that it would not affect how we use.


Inheritance

Objects are alike in object oriented programming that they share similar logic. To avoid reuse the similar logic and withdraw specific logic into other class, we use inheritance.

For example, we build a child class by extracting from another parent class. Chain of command will be formed.

All fields are reused by the child class and method of the parent class common part and can implement its own unique part. If the program needs to lead both private or public teachers (both private and public teacher is a type of teacher) and also need to manage students, it will form a chain of command.


Polymorphism

Polymorphism can let you assess the class like parent. Therefore, it would not have any problem even when the types are mixed. When you define a parent interface, it will have a list of similar methods. Every child class appliance their version of these methods.



11 views0 comments

Comments


bottom of page