How to design a class?

"Start with the simplest thing that works. That thing will probably be just a function. Grow it from there. If it gets too big, split it. If you find that you pass the same 12 parameters to a bunch of functions - factor out a class. If you do the same thing in a bunch of classes - abstract it out. Keep it DRY. Keep it SOLID. Rinse and repeat. This way you end up with a useful class hierarchy - and OOP won't be awful."
-- azov, emphasis added
I like his approach, build working stuff incrementally, from procedural towards Object-Oriented (OO) design when needed compare to the more theoretical and classical way on how to design a class. Way more pragmatic for those coming from more procedural experiences. Based on my observation, some programmers still struggle on adapting an OO mindset. There is nothing wrong with procedural approach but if you're using a framework, at least try to understand and follow the underlying OO structure.

No comments:

Post a Comment