Is OOP Dead?

Aditya Purwa
2 min readApr 1, 2018

--

Well, no.

The explosion of JavaScript has turned people against object oriented because they think JavaScript is not object oriented and they think functional programming solve everything.

Even people who used to work with object oriented language that moved into JavaScript also expressed this feelings.

The thing is, JavaScript is object oriented. Not in the same implementation of any other object oriented language. But it is still object oriented, by the defintion, anything that is not a primtive type is considered as an object. Function is an object, primitive types eventually boxed in object like structure.

Im not bashing functional programming nor JavaScript here, I am using it for my work, enjoyed it. However, the reverse seems to be not true for JavaScript developer working on object oriented language. Can’t enjoy it?

The problem with object oriented is that people often missuse it. The infamous problem of scanner and copier to discuss the problem of inheritance.

class PoweredMachine{
start()
}
class Scanner: PoweredMachine{
@start()
}
class Printer: PoweredMachine{
@start()
}
class Copier: Scanner & Printer{}

What happen if you call start on copier? Will it call start of scanner or printer? Duh, you know your design is wrong when you have to do multiple inheritance. Copier is not a device that is a scanner, nor a printer. It is another device that can do stuff that scanner does, and printer does, and combine both of them when needed. Copier is a composition of scanner and printer.

Its only right if you define Copier as below:

class Copier: PoweredMachine {
scanner: Scanner
printer: Printer
@start(){
scanner.start()
scanner.onFinished( data => printer.print(data))
}
}

But what about inheritance that spans into like 1000 children, well, its the same issue if you have a composition that spans into like 1000 children. Clearly, you’re in deep mess if you have inheritance or composition that spans into so many unmanageable children.

Tips, if you can use interface, use it, and if you have to use class, try to make it abstract, if you are extending a non-abstract class, please rethink again about the design.

People seems to be frustated because they don’t understand how to use object oriented language properly, and its true that its not always easy to properly design your system. So, it is easier to stick with functional programming model as it is easier to understand, and yes, could produce less bugs than object oriented. I’ve been there, it took me 3 years to understand object oriented paradigm.

If object oriented makes sense, use it, if functional model makes sense, use it. It doesn’t have to be OOP vs FP, its always been OOP + FP.

So no, OOP was never alive, so it will never be dead. FP or OOP is not the solution, it is a way for you to write the solution.

--

--

Aditya Purwa

Building Playtune (https://playtune.app) - Software engineer, writer, designer, and artist.