Hello world, I’m Kalana Gayanga Rathnayake. In this blog, I will explain about OOP concept. The basic foundation of many object-oriented languages such as Java, C++, and C# is object-oriented concept. Flexibility and maintainability are the primary purpose of the OOP.

Before we start discuss about this, lets talk about “objects” and “classes”.

Class..
A class acts as a blueprint where determines properties and methods familiar to all java objects of a specific kind.

Object (Data members)..
An object specifies the instances for a class which are represented in the real-world objects that we can find in everyday life.

The four Pillars of Object Orientation.

There are four main elemental concepts in OOC that increases the readability and maintainability of any program. They are,

1 ) Encapsulation
2 ) Abstraction
3 ) Inheritance
4 ) Polymorphism

Lets talk about these Concepts one by one.

1. Encapsulation

Encapsulation is described as the wrapping up of data following a particular unit. It is the mechanism that binds the united code and the data it manipulates. Another method to think about encapsulation is, it is a protective guard that blocks the data from being reached by the code outside this protection.
When we study Java, They are access modifiers and helps to implement Encapsulation. They tell the compiler which other classes should have access to the field or method being defined. They are,

1. Private - Last access, best encapsulation
2. Protected - Some access, Moderate encapsulation
3. Public - Full access, no encapsulation

Lets discuss about those main three access modifiers.

  1. “Private” access modifier.
    Private classes can only be nested within another class and are prohibited outside of that scope. It is not probable to declare a standalone class with this modifier. Private classes encapsulate functionality that is particular to the class where they were declared.
  2. “Protected” access modifier.
    The protected access modifier is available within a package and outside the package but through inheritance only.
    The protected access modifier can be applied to the data member, method, and constructor. It can’t be applied to the class.
    It provides more accessibility than the default modifier.
  3. “Public” access modifier.
    Public classes are noticeable to everyone and not limited in any way. Public branches are noticeable inside and outside the class in which they were declared.
    Branch variables are not typically defined with a public scope as this explanation would allow unrestricted access to an object’s state. Member variables are kept private.

2. Abstraction

In object-oriented programming languages, Abstraction is one of the primary concepts. Handling complexity by hiding unnecessary details from users is the main goal of this concept. That facilitates the user to implement more complex logic on top of the provided abstraction without understanding or even thinking about all the hidden complexity. That’s a very universal concept that’s not restricted to object-oriented programming. You can find it everywhere in the real world.

Let’s get a real-life example of Abstraction, which is an ATM Machine; All are performing operations on the ATM-like cash withdrawal, money transfer, retrieve mini-statement…etc. but we can’t know internal details about ATM.

3. Polymorphism

Polymorphism is the ability of an object to take many forms. Literally polymorphism is the capability of a method to behave in many forms depending on the object it is been created on object.

There are two main types of Polymorphism

  1. Compile time Polymorphism (Static Binding)
  2. Runtime Polymorphism (Dynamic Binding)

Compile-Time Polymorphism

Compile-time Polymorphism is the sort of polymorphism that is determined during the compile time. This tool is also recognized as the ‘Static Binding’.

As an example Method Overloading is a good example for this sort.

Run-time Polymorphism

It is also known as Dynamic Method Dispatch.

Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime, that's why it is called runtime polymorphism. I have already discussed method overriding in detail in a separate tutorial, refer it: Method Overriding in Java.

Dynamic Method Dispatch is a another name to call this kind of polymorphism. This method

Inheritance

Inheritance is a tool for obtaining the features and behaviors of a class by a different class. The class whose segments are inherited is called the base class, and the class that inherits those segments is called the derived class. Inheritance performs the IS-A relationship.

There are six types of inheritance.

  1. Single inheritance
  2. Multi-level inheritance
  3. Multiple inheritance
  4. Multiple inheritance
  5. Hierarchical Inheritance
  6. Hybrid Inheritance

So that’s simply the basics of object-oriented programming concepts. I hope this article would help with your knowledge. Thank You for reading and Have a nice day!

Software Engineering undergraduate of Sri Lanka Institute of Information Technology