Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
16

Is it a good coding style? From my point of view neither of your versions is. First having to call setQuality before letDoIt can be called is a temporal coupling. You're stuck viewing DoItThisWay as an derivative of DoSomething, but it isn't (at least not functionally), it's rather something like a interface DoSomethingWithQuality { void letDoIt(String ...


11

Let's assume quality cannot be passed into the constructor, and the call to setQuality is required. Currently, a code snippet like int quality = obtainQualityInfo(); worker = new DoItThisWay(); ((DoItThisWay) worker).setQuality(quality); is way too small to invest too much thoughts into it. IMHO it looks a little bit ugly, but not really hard ...


5

I'm assuming that quality needs to be set alongside each letDoIt() call on a DoItThisWay(). The issue I see arising here is this: You are introducing temporal coupling (i.e. what happends if you forget to call setQuality() before calling letDoIt() on a DoItThisWay?). And the implementations for DoItThisWay and DoItThatWay are diverging (one needs to have ...


2

A common interface where the initialization varies based on runtime data usually lends itself to the factory pattern. DoThingsFactory factory = new DoThingsFactory(thingThatProvidesQuality); DoSomething doSomething = factory.getDoer(info); doSomething.letDoIt(); Then DoThingsFactory can worry about getting and setting the quality information inside the ...


Only top voted, non community-wiki answers of a minimum length are eligible