Object Oriented Programming Kotlin (Part:01)

By | October 14, 2017

Object Oriented Programming Kotlin (Part:01)

Kotlin language supports OOP (Object Orientated Programming). Before writing any OOP code we first need to know why object oriented programming in kotlin is needed. We can solve any type of problem using procedural oriented way. So why we learn object oriented programming .

For a simple example we learn the answer of why . Let a organization has 200 members. your boss tell you write a application which get every employee’s name and output their full name and reverse name .

In procedural oriented way you write code this way. Suppose we mansion first 5 members name as: MD John Ahamed, Mr Sunil , Md Humayun Ahamed, Mr Sourav Saha , Md Arif Hossain .

you write code

every employee sense you write 5 lines of code . So 200 employee you need 200*5 = 1000 line of code. One another issue is if 2 people has same name how to manage . This code indicating for deeper problem in the system also known bad smell of code.

So how we solve this problem . Now solving this type of problem object oriented programming is needed.

If we create a structure for every employee and reuse this structure for every employee sense that solve our problem.

The structure which is used every employee sense it called Class

Everything in this world is Object . kotlin object has two part:

  • has
  • does()

suppose Laptop is a object , why it is object

  • laptop
    • has (mouse, keyboard, speaker, processor, ram …… many more )
    • does( solve mathmatical problem, listening music , playing games etc)

has means which element present in this object and does means which work is done .

Here we think more object

  • Shop is a object
    • has ( goods, employee, computer, a room etc ….)
    • does( provide everyday’s need etc..)
  • Dream is a object
    • has ( a subject  )
    • does( provide feel, emotion etc..)

seen and unseen every element in this word is object . So try to find out 10 element which is object and tell me why it is object.

kotlin Class: a class is the blueprint of object

Object Oriented Programming in Kotlin is one of the most important topic in kotlin language.

Object Oriented Programming in kotlin links:

No more today . Next post  we will solve our previous problem in OOP way

Leave a Reply