News for hackers. Stuff that matters.
Re:Ask HN: Any Tips for Understanding OOP? by noduerme on Friday June 11, 2021 @04:21AM (#27470620)
You can certainly write any end product without OOP as you could with it. I happen to like OOP because I think more visually and geometrically than linearly. My answer to your question about how to write clear code that maximizes OOP's usefulness is to constantly consider what attributes in subclasses you can or should push up the inheritance chain. For example, I spent a long time working on a piece of software that had pop questions, quizzes, and tests separated into different kinds of objects and database structures. Getting familiar with the commonalities and differences between these user interactions, I was able to restructure the code so that tests extended quizzes, which were a collection of questions paired with answers and users. Maybe this should have seemed obvious to the original coder, but when things grow organically you don't always design them in the ideal way. Restructuring that helped me migrate the database to a simpler, cleaner set of connecting tables that then helped expose a lot of data (user performance) that was much harder to tease out previously. So to me, OOP is more a way of getting at the truth of business / application logic. When trying to solve a small problem, I often write functional inline code. But on a large scale I use objects to clarify the relationships between real world artifacts.

There are no comments on this comment yet.