3 ms·
This is all nonsense anyway. There's no such thing as a TwitterUser or an EmailUser. You just have users, some of whom use Twitter, some use email (and may have
by skybrian 14y ago
This is all nonsense anyway. There's no such thing as a TwitterUser or an EmailUser. You just have users, some of whom use Twitter, some use email (and may have multiple addresses), and some use both, and they can edit their settings to add and remove accounts and change notification preferences. So it's really has-a rather than is-a.
Adding unnecessary inheritance is far worse than the original problem.
- hajrice 14y agoI completely agree with you. I actually find the 'cleaner version' much much harder to read. Every time I look at the code I have to 'recompile' it in my brain, just because it's doing such a simple thing in such a darn complex way.
- ed_blackburn 14y agoI suspect the author is trying to use trivial examples to highlight the pattern. As with everything it's about judgement. If you're going to inherit another type be sure to observe Liskov Substitution Principle, otherwise in avoiding conditionals you're introducing another approach that will lead you towards entropy. That is after all what many of these principles are for isn't it? reduce entropy. Writing the code is easy, maintaining and adding crazy new features from the pesky business is where it gets expensive? Entropy kills apps. In my experience observing (pragmatically, never dogmatically) OO principles like SOLID reduces entropy. Thus are worth applying. Personally I prefer polymorphism and null object pattern over conditionals to deal with edge cases, though if you have a leaky abstraction in the first place no principle or pattern is going to save you!