r/programming • u/javinpaul • May 05 '19
10 OOP Design Principles Programmer Should Know
https://hackernoon.com/10-oop-design-principles-every-programmer-should-know-f187436caf65
2
Upvotes
r/programming • u/javinpaul • May 05 '19
1
u/Zardotab May 06 '19 edited May 06 '19
I disagree, that creates a lot of verbosity, which slows reading and creates more room for typos. Wait until there is an actual reason or a high likelihood of need. Other languages allow one to switch to accessors under the hood without changing caller code by making a method versus property an interface issue or one in the same (swappable). For example, in "a=x.foo;", "foo" can be a method or attribute. If you start out with "naked" attributes and later need to wrap it, you usually can without reworking code that references "foo". You don't have to "pre-bloat" your code with accessors to achieve that. Java is flawed this way in my opinion, and I hope they fix it. Pre-wrapping everything "just in case" is a bad practice.
The rest of the examples rely too much on shapes, which don't make good examples because in the real world, the subject matter changes more frequently. The rules of geometry are too static to be a good test. I realize they are just training examples, but I've seen people mis-apply lessons learned from shapes into the real world.
And be very careful about splitting domain things into "types". Often that's too blunt of a model. A buffet of features assigned to objects is more flexible. It's similar to the article's Rule 6: "Favor Composition over Inheritance." However, OOP is lousy at set theory in my opinion in order to manage the features as sets. I'd like to see relational modelling extended into code structuring: table oriented programming. OOP is not powerful enough without reinventing a database in it.