Table of contents
This article is primarily aimed at those who have a theoretical understanding of Object Oriented Programming (OOP) but are unable to use it in the actual world or in programming. Let's have a look at what OOP ideas are.
INHERITENCE
Deriving a new class from the existing class is called Inheritance.
Syntax of Inheritence in Java
class BaseClass
{
//methods and fields
}
class DerivedClass extends BaseClass
{
//methods and fields
}
Real life Examples -
👨👩👧👦Child and Parents: All the properties of parents are inherited by their son/daughter. They have same features but are not same, they are identical.
POLYMORPHISIM
The word Polymorphism can be broken into two words – ‘poly’ means ‘many’ and ‘morph’ means ‘forms’. So, polymorphism means many forms. Polymorphism means ability to take more than one form that an operation can exhibit different behavior at different instance depend upon the data passed in the operation.
Real life Examples -
👦Duties performed by a man. Man is only one, but he takes multiple roles like - he is a dad to his child, he is an employee, a brother, and many more.
🏟Stadium: Consider the stadium of common wealth games. Single stadium but it perform multiple task like swimming, lawn tennis etc.
🙉Sound of animals: People have the same sound but different animals make different sounds. The following diagram shows few different sounds make by animals.
💂♂️Behavior of Security Guard: A security guard outside an organization behaves differently with different people entering the organization. He acts in a different way when the Boss comes and, in another way when the employees come. When the customers enter, the guard will respond differently. So here, the behavior of the guard is in various forms, which depends on the member who is coming.
ENCAPSULATION
Encapsulation means it binds data and code together into one unit.
Real life Examples -
💊Capsule: A capsule binds all it's medicine material within it just like java encapsulation units bind all it's data and behavior within it.
🚗Car: A car is having multiple parts like steering, wheels, engine etc., which binds together to form a single object that is car. So, Here multiple parts of cars encapsulates itself together to form a single object that is Car.
🏢Large organization: An organization is consists of several departments like the production department, purchase department, sales department, and Accounts department. It combines all these departments together and had formed the organization.
ABSTRACTION
Abstraction means showing essential features and hiding non-essential features to the user.
Syntax of declaring an abstract class:
abstract class ClassName
{
//class body
}
Real life Examples -
🏧ATM machine: We don't know internally what things are happening inside ATM machine when we insert an ATM card for performing any kind of operation.
🖥Tv Remote: Remote is a interface between user and tv, right. which has buttons like 0 to 10 ,on /of etc but we don't know circuits inside remote. User does not need to know. Just he is using essential thing that is remote.
📱Mobile phones: On a mobile phone, we can perform so many actions like making a call, sending messages, take pictures, download software and etc. We perform a lot of things but here also we don't know the inside process of these things. Which means the implementation parts are hidden.
SUMMARY
- Inheritence -- One property of object is acquiring to another property of object
- Encapsulation -- Protecting our Data
- Polymorphism -- Different behaviors at different instances
- Abstraction -- Hiding our irrelevant Data
Following the above idea and remembering the four OOPS pillars will help you create a successful software and relate it to the actual world. I hope you enjoyed reading this article. Don't forget to express your thoughts, whether positive or negative. In any case, sharing is beneficial.