When I started coming across articles about Object Oriented Design (or Object Oriented Programming) being dead, I found it very unsettling. A huge amount of the industry we work in is founded upon this design principle! What is to become of us?! Or could this just be the hype train again? Fake news? Well let’s talk about that and come to our own conclusions.
What Even is OOD?
Wikipedia gives us a good page on the topic, but to save you the reading a basic definition would be:
‘A method of Software design in which the components are implemented as objects with their own behaviours and internal states’
Now before you type up a comment starting with the words “well actually”, I am aware that the man who first coined the phrase, Alan Kay, had a very different definition. However, the concept has evolved since 1966. (Here’s a decent Stack Exchange page on the subject as I fear it is way out of scope for this post.) I guess what is really important to understand is, why OOD has become so popular as a modern software design paradigm. In my opinion, the answer is:
‘OOD minimises the cognisant complexity of a software system by using real world analogies’
In other words, OOD’s main advantage is that, when employed correctly, the resulting code is easy to understand. As a quick example some code for an employee might be something like:
private String name
private int salary
private Date startDate
private Date endDate
def calculateBonus(int percentage) :
return (salary * percentage) / 100
def terminateEmployment() :
endDate = now()
Criticisms of OOD
There have been a number of articles on how OOD is dead, and to be honest a lot of the messages don’t really ring true for me; call it a differing of opinions. Here are my two cents on the main criticisms of OOD I have heard and read:
- Inheritance promotes tight coupling and tight coupling is bad
Well yes, it does, and yes it is, and yes you’ll find that inheritance is rarely used as a result. However, the few times I have used it it has saved me a lot of typing and left me with code that was much more concise than if I had to make wrapper objects or duplicate all the data I cared about. The fact is sometimes data and/or functionality by its very nature is tightly coupled with other pieces of data/functionality. Consider an admin app and the screen for managing a user account. Say we need another for screen dealing with requests to update account details. It sure sounds like the functionality of the latter is a superset of the former…
Anyway, my point is that inheritance is a useful tool I’d rather not be deprived of.
- Encapsulation doesn’t protect your state
Frankly, yes, you are right, there are ways around the encapsulation , but we are not building little safes here, we are writing legible code. If someone else comes after you and breaks all your lovely design to get at some value they should not have access to, that’s their problem. Most of the time they will have to resort to reflection, so it should be obvious to subsequent Developers who see that code, that someone is being naughty.
Where Did This Debate Come From?
The world of software is changing… Well that was a redundant sentence, but what I want to talk about is the fact that our machines are getting faster and faster, while getting cheaper and cheaper. Cloud services allow us to basically rent huge hardware resources for short periods to do some fairly amazing things. I am, of course, talking about Big Data and Machine Learning. These are problems that most traditional object oriented languages are not suited to dealing with, at which point functional programming languages and languages which specialise in multiprocessing, come to the rescue. For this reason we have seen more and more market share moving from languages like Java and C# to Python and Golang.
So, Do I Think It’s Really Dead?
Overall, this is my response to certain articles which express the belief that OOD is indeed dead. When it comes down to it, I believe it’s a matter of using the right tool for the job. To the question of ‘is Object Oriented Design dead’; I think my opinion is obvious here, but let me answer the question with another question. Is it still preferable for applications to have code that is easily maintained? That’s why we’re using OOD, and there’s not currently a competing model for designing easily maintainable code. Will the majority of applications ever need to deal with Big Data or multi-processing? No. That’s silly. Don’t be silly.