Is the Object-Oriented Paradigm a False Hope?
Does OOP live up to the hype?
Join the DZone community and get the full member experience.
Join For FreeFor the last 20 years, Java has become the most popular object-oriented language. It conquered the enterprise world and still has one of the biggest communities. Now industrial development exists only because of the object-oriented paradigm (OOP). But here, I want to bring up skepticism about its fundamental paradigm. First, let's return to the past when Java didn't exist.
You may also like: Misunderstanding OO Programming
Historical Reference
1985 — the is the year when C++ was released the first time. C++ supported an object-oriented model and even had generics. The object-oriented design was becoming more and more popular. In 1994, the most popular book about design patterns was published, called the "Gang of Four (GOF)." GOF is still one of the most famous and recognizable books on design patterns (with about 23 patterns total).
Later, in 1995, Java 1.0 was released. It was a significant milestone for OOP, being the first completely object-oriented language. Java established the idea that "everything" is an object, and thus helped spread the OOP idea around the world.
Ambiguity of Patterns
In theory, each pattern is represented by a simple structure that is transparent to anyone. But in reality, the situation is quite different:
Some patterns became anti-pattern or irrelevant (e.g. the strategy pattern lost all value after Java 8 due to the Supplier interface)
Many patterns are recognized differently by developers, especially in terms of pattern usage
Some patterns have no practical value and exist only as a museum piece
Only on Wiki does the number of patterns exceed more than 50. But, in actual Java, only 13 keywords are responsible for the object structure, and among them, only 10 are generally used.
Object-Oriented Pollution
Unfortunately, the majority of enterprise projects become unsupportable quite rapidly. As a consequence, many enterprise projects are facing a constant migration process and unacceptable timelines. And sometimes, bug-fix estimation takes more time than simply re-writing from scratch.
In addition, the word "legacy" scares IT employees more than ever before. According to my experience (more than 30 enterprise projects), the key problem is the project's architecture, which looks like a mess of patterns than anything else.
Cargo Cult
Often, many patterns are used inappropriately or without any purpose, and this is all so that they can follow "modern OOP trends," sometimes referred to as the OOP cargo cult.
Procedural Style
In procedural development, the key logic is stored in functions. Functions "communicate" with each other by sending and receiving parameters, AKA "messages". The global status contains arrays, structs, or constants — pure data.
OOP Style
In the object-oriented world, the program is based on its structure (objects). Functions are playing a secondary role and just change the state of objects. And an objects' state orchestrates the application. Logic became distributed between functions and structures.
Salary Calculator Program in Procedural Style
Everything is transparent. 4 parameters = input and 1 = output. Nothing to add.
Salary Calculator Program in OOP style
Looks easy, but we ignored the encapsulated part:
How to Avoid the OOP Curse?
- Use a pattern with a full understanding of its purpose — no cargo cult!
- Do not shift logic in the object, if it's possible
- Use functional features, Akka Streams, and method references to methods
- Do not be afraid to write average size methods, e.g. 50 lines
- Use pure methods without changing state inside (pass only by value and return value)
- Do not spread one functionality between many layers. Maintain visibility.
Further Reading
Misunderstanding OO Programming
A Systematic Approach to Write Better Code With OOP Concepts
Opinions expressed by DZone contributors are their own.
Trending
-
Measuring Service Performance: The Whys and Hows
-
DevOps Pipeline and Its Essential Tools
-
How To Backup and Restore a PostgreSQL Database
-
RBAC With API Gateway and Open Policy Agent (OPA)
Comments