HACKER Q&A
📣 culopatin

How do I know if OOP is what I need?


I am a beginner and I'm building an application that stores DNA sequences in a SQL database. I've been using Java because I'd like to have it in my portfolio to make a lateral move in my company.

The material I've been using to learn Java teaches OOP concepts, of which I barely grasp thinking in terms of objects and classes.

Is this still the preferred way of thinking or in 2021 there is a better model to follow?

Thanks


  👤 BjoernKW Accepted Answer ✓
There's nothing wrong with using OOP in 2021.

The key features of OOP are encapsulation of data (properties and the actions to perform on those are hidden from the implementing code) and polymorphism (different interchangeable implementations of the same interface, which in turn enables patterns such as dependency injection).

With OOP data typically is mutable whereas with paradigms such as Functional Programming (FP) data usually is immutable.

These features might or might not lend themselves to what you're trying to achieve. It's not so much a question of the data you're going to store but what your application is supposed to do with that data (other than storing it, that is).

You might want to look into data structures that are particularly conducive to storing DNA data. DNA sequences in some ways are similar to natural language, which is why data structures that are commonly used for storing natural language (such as tries, for example) are useful for storing DNA data, too.


👤 bsldld
I am a C++ developer. Most of the time I have developed OO applications. But recently while developing web backend using C++, it becomes very difficult to think in terms of OO. As one starts programming web app it soon becomes clear that the web is fundamentally functional in nature, the way it is designed. So it becomes difficult for me to map the C++ OO concepts to the functional nature of the web architecture.

Now, this type of realisation comes only after you have done enough programming in one of the programming paradigm(OO or FP), and have at least some understanding of the other.

If you are using Java for career progression, then stick with it. But if you want to be able to decide on whether OO or FP is useful for a project, then that comes from practice. So practice on paradigm and have some understanding of the other. That makes it easy for decision making.


👤 lastofus
Check out “99 bottles of OOP” by Sandi Metz for a fantastic beginner friendly book on OOP concepts.

It does a great job of starting you from first principles and showing you not just the how, but the why of applying OOP to solve problems.


👤 russianator
Not everything needs abstraction.

FP (Functional Programming) has it's place. Sometimes a pure function is a beautiful thing to have.

It's also ok to mix OOP and FP.


👤 theandrewbailey
There might be a more 'innovative' way of doing it, but Java is an adequate choice for this problem. (sounds like CRUD?) If you're doing it to add to your resume/CV, even better. Java isn't hot tech, but it will pay the bills.

👤 gitgud
From my experience OOP is good when you're trying to simulate reality in virtual space. Say a game with different objects and state.

If you're not simulating anything, then perhaps a functional approach is easier and less confusing for the reader.


👤 aristofun
With java you don’t really have much choice. It’s OOP by design.

As most of current programming languages and production systems.