Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • It's a good point, and certainly I agree some times it isn't accidental and has given me pause and resulted in me refactoring something. That being said, I think this command pattern for example could seem to me in some circumstances a little artificial. Suppose I just have some singleton instances of certain classes, these classes have many methods, and I just want to use one. Does it really make sense to wrap these classes in some other classes just to achieve polymorphism in this place? I'm certainly open to the idea, but I'd like to hear an argument for it. Thanks for the links. Commented Jun 12, 2020 at 17:38
  • 1
    @KircheisVent Far from me the idea of promoting polymorphism at all costs! On contrary, I’m a strong believer of composition over inheritance. Polymorphism should be used only if there is a strong reason and a real is-a relationship (e.g. drag_event_processor is-an event_processor). But when structurally polymorphism emerges, it’s a sign that shall not be ignored. Maybe it’s coincidence and forget about it, but often it’s a gut feeling that make you realize a hidden connection that will enlighten your vision on your design. Commented Jun 12, 2020 at 18:31
  • 1
    @KircheisVent Additional hint: speaking of artificial, and pardon me if I’m provocative, but if it appears that you have lots of singletons in your design, there might be something fishy going on, because singletons should really be the exception and not the rule. Not knowing anything about your design, I cannot advise you on that nor strongly recommend not to use them (your design, your choice), but maybe give a critical thought to it. Commented Jun 12, 2020 at 18:37
  • 1
    No provocation. It's a good point. I take no real criticism from it because these situations usually arise in established JavaScript projects I am thrust into. I do find I don't get myself into these scenarios in my other work. Sometimes the design of these JavaScript projects is so alien to me as to leave me feeling quite unsure of myself. Commented Jun 12, 2020 at 18:54