r/learnjava • u/SadCar1494 • 29d 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?
View all comments
10
u/CantRunNoMore 28d ago
There is an old statement - a class should do one thing and one thing well.
I loved OOP at Uni and then in industry found a lot of it to be BS.
The idea is correct, you move the language close to the problem domain. So you end up being taught over simplifications, a Car class, a Color, a Flower etc. In real life application may have Account, Statement etc but the trap is in inheriting from such classes.
If a class doesn't fully satisfy the is-a relationship then do not inherit from it. You can see when this isn't working well when you see code that uses instanceof to determine what type of object they are dealing with rather than using simple polymorphism.
Moving forward I would look at design patterns and see how the power is in polymorphism and not via inheritence