Learning: Object Orientated Programming

Learning: Object Orientated Programming

Home \ Journal \ Learning: Object Orientated Programming
Published: 06/08/2019

Learn & Understand:

  1. Abstraction (which will help understand Dependency Inversion Principle of the SOLID principles)
  2. Encapsulation
  3. Inheritance
  4. Polymorphism

OOP Features

Object Oriented Programming (OOP) is a programming model where programs are organised around objects and data rather than action and logic.

Software is divided into a number of small units called objects. The data and functins are built around these objects.

The data of objects can be accessed only by the functions associated with that object.

The functions of one object can access the functions of another object.


A class is the core of any modern Object Oriented Programming language. In OOP languages it is mandatory to create a class for representing data.

A class is a blueprint of an object that contains variables for storing data and functions to perform operations on the data. A class will not occupy any memory space and hence it is only a logical representation of data.

To create a class you simply use the word "Class" followed by the class name:



Objects are the basic run-time entities of an object oriented system. An object is called as run time entity because it is assigned memory dynamically during run time. Objects may represent a person, a place or any item that the program must handle.

"An object is a software bundle of related variable and methods."

"An object is an instance of a class"

When an object is created using the new operator, memory is allocated for the class in the heap, the object is called an instance and its starting address will be stored in the object in stack memory.

When an object is created without the new operator, memory will not be allocated in the heap, in other words an instance will not be created and the object in the stack contains the value null.

Syntax to create an object of class Employee:



An abstract class is considerered a class that consists of common data.


If somebody in your college tells you to fill in an application form, you will provide your details, like name, address, date of birth, which semester, percentage you have etcetera.

If some doctor gives you an application to fill in the details, you will provide the details, like name, address, date of birth, blood group, height and weight.

See in the preceding example what is in common? Age, name and address... so you can create a class that consists of the common data. That is called an abstract class.

Working example: MobilePhone {} is the abstract class as it contains two item of common data.



Encapsulation is a technique used to protect the information in an object from another object.

It means hiding the internal details of an object, in other words how an object does something and prevents clients from seeing its inside view, where the behavior of the abstraction is implemented.

Working example:



When a class includes a property of another class it is known as inheritance. It's a process of object reusability.

For example, a child includes the properties of its parents.



Polymorphism means one name, many forms. One function behaves in different forms.

In other words, "Many forms of a single object is called Polymorphism."


Your mobile phone, one name but many forms:

  1. As phone
  2. As camera
  3. As mp3 player
  4. As radio


If you're a skilled developer, you may have noticed this is 1) Extremely Basic & 2) Mostly taken from other online sources. These are the notes I made while studying and would like to remember, so often I make notes and either never look at them again or completely misplace them. 

Thanks to this journal that is now a thing of the past.