Object Oriented Programming in Kotlin (Part:02)

By | October 14, 2017

Object Oriented Programming in Kotlin (Part:02)

In previous part, we already had discuss why object oriented programming in kotlin is needed then started discussion about kotlin Class, kotlin Object.  Every object has two parts:

  • has: “has” means which element present in this object
  • does(): “does” means which work is done.

In this part, we will try to solve our previous problem in OOP way.

kotlin Class VS kotlin Object


now this part we solve this problem in Object Oriented way . First we need to create a structure with represent 200 employee . If you think a plastic manufacturer company first create a dice , then they use this dice to rebuilt all the same type plastic product. So its same to our code . We need to create a dice for every employee . so we create a class ( a class is the blueprint of object)

 right click kotlin folder then select kotlin file/class => dialog provide a class name. Here we write Employee ( it is best practice in every programming language Class name must be PasalCase (first character capitalize) ) 


has value also called field value, property

does()  also called method

Now we change our code in OOP pattern . Here every employee is a object of Employee class.
It is the beauty of object oriented programming in kotlin . Next tutorial we refactor our code in more structural way.

Object Oriented Programming in kotlin links:

Happy Coding!!!

Leave a Reply