r/learnjava • • 28d ago

OOP DESIGN

I've been learning Java for about a month now. So far I've covered OOP principles, Java Collections, and I'm planning to dive deeper into exception handling next.

However, one area where I still struggle is OOP design and structuring. I understand concepts like inheritance, encapsulation, abstraction, and polymorphism, but when it comes to applying them in actual projects, I often find myself struggling to distribute them properly among classes.

No matter how many classes I create to separate different parts of the logic, I eventually end up with at least one class containing too many methods and responsibilities.

What are the best practices, concepts, or design principles I should study to improve my OOP design skills? How can I develop the ability to identify when a class is doing too much, decide when to create new classes, and structure a Java application in a clean, maintainable, and scalable way?

14 Upvotes

16 comments sorted by

View all comments

1

u/Dedios1 27d ago

I like to think of code like an extension of data. If you’re familiar with databases and normalization, you know that a table should have one purpose. Example don’t mix messages and who sent them in the same table. They should be separate. Then you create relationships between them (equivalent for coding is inheritance polymorphism etc). 🤷🏽‍♂️

But again it won’t feel natural without writing more code. Just write code. You’ll start to gain the intuition for structuring/modularize your code. What matters is that it’s readable AND you know exactly where to go to fix a bug or at least diagnose. You can actually edit code forever. Big PR differences between year 2-3 and year 10 😂