Object oriented Programming

Kotlin is an Object Oriented Programming(OOP) Language, but it also has the advantages of functional Programming

Object oriented programming, as it's name suggests, is based around representing some parts of a code as objects. Objects have their properties and functionalities that define them.

Object oriented programming is a way of giving more importance to the data than the sequence of the code.

The real world is a collection of objects which interact with each other to form an environment. These objects have certain features and certain functions that define the object the way it is.

For example, a microwave oven has certain features, such as it’s model number, it's capacity, the current heating temperature etc. It's function includes switching on, heating it’s contents, setting the timer, etc.

In programming, the microwave can be an object with it’s features as it’s data members and it’s functions as it’s member functions.

The features of a microwave can be altered only by it’s functional units and not by anyone or anything external to the microwave itself. This is true in programming sense too. This is also known as abstraction and encapsulation.

Abstraction is the process of hiding data that is not necessary for the user to know about. The internal working of a microwave needn’t be known to us for it’s operation.

Encapsulation is the concept of binding the data members along with it’s member functions into one single unit, as the name suggests. The working of a microwave can only be controlled by it’s member functions, i.e. the buttons.

Object oriented programming involves several concepts:

  • Abstraction
  • Encapsulation
  • Polymorphism
  • Modularity
  • Inheritance

A class is a template, whose instances are called objects.

In the above example, microwave is a class. Objects of microwave can refer to it’s different models. The data members of an object can hold different values, which differentiates it from other objects (apart from it’s name).

The real world relations can be very important in programming as the code written ultimately is to be run in the real world for real purposes.

Hence, to maintain their integrity and the relations between different objects, it is necessary to model our programming paradigm to simulate the real world.

Every thing in this world can be decomposed into several objects which may or may not interact. This follows the base for OOP.

Object oriented programming allows models to be created that separate data and behavior of one object from the data and behavior of other objects. This is the fundamental principle behind object-oriented programming.

Features of object oriented programming are :

  • Emphasis is on data rather than procedure.
  • Programs are divided into what are known as objects.
  • Data structures are designed such that they characterize the objects.
  • Functions that operate on the data of an object are ties together in the data structure.
  • Data is hidden and cannot be accessed by external function.
  • Objects may communicate with each other through function.
  • New data and functions can be easily added whenever necessary.
  • Follows bottom up approach in program design.

Classes in kotlin

Pillars of Object Oriented Programming


Pick out common features of objects and procedures. That means you can create a base class (object if you will) that defines shared features of all classes that inherits from it.

E.G. : Abstract class shape has functions to calculate area, all objects like circle, square and so on inherits shape and therefore should also allow one to calculate are, possibly with custom implementation.


The process of combining elements to create a new entity. Brutally simple construct.

It means that instead of writing complicated expressions over and over again, you encapsulate them, make the reusable more easily.


Classes can inherit one another taking on functionality of the predecessor. Functions and properties can be overridden, new constructors can be created. New features can be easily implemented by inheriting existing classes.

Polymorphism :

Polymorphism means that different objects can implement the same thing in different ways. You have a class 'Animal', and all animals can make a sound. So you give them the makeASound()-method.

When you have a dog, it will inherit all properties and methods from 'Animal', so also the makeASound()-method. You can fill this method in by letting it bark.

When you have a cat you would also let it inherit from 'Animal', but instead of barking it will meow at the makeASound()-method. Although it's the same method, different children can implement it in different ways.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

Join My Facebook Group
Join Group