4 ms·
If my BubbleMachine currently makes SoapBubbles, but I want it to be able to make GumBubbles as well, who, out of those three, is responsible for overriding the
by LgWoodenBadger 7y ago
If my BubbleMachine currently makes SoapBubbles, but I want it to be able to make GumBubbles as well, who, out of those three, is responsible for overriding the “new” method to create GumBubbles instead of SoapBubbles?
- spankalee 7y agoA Bubbles class, which is basically the same as a factory. I don't see a huge difference in practice myself.
- matheusmoreira 7y agoAre these all subclasses of a Bubbles class? I think that'd be the natural place for a custom new method that figures out which subclass to construct based on the parameters. In Java, an interface could have a static method that returns concrete implementations of itself.
- scroot 7y agoIt's even better. If it's just making stuff, you don't even need `BubbleMachine` if you have the `Bubbles` base class. You can add creation method on the class side of `Bubbles` like so: `Bubbles class >> #newGum` ^ GumBubbles new `Bubbles class >> #newSoap` ^ SoapBubbles new The difference here is that the base class still serves as a true base: it will have all the common functionality for various kinds of bubbles