(i’m not sure if thats a good title here (because its a very abstract topic), feel free to change it, if you have a better one)
I have a thing (i dont want to call it controller, so thing)
So this thing you can send the following messages:
t.trySet("knob 1", true);
t.trySet ("knob n", false);
t.setAllKnobsTo(true)//maybe the thing decide only set the minimum possible knobs to true
As you can see here, the
try could mean that the setting fails. The
thing also can do there some more, maybe if it set
knob 1 to
true, it decide also to set
knob 5 and
However, i think its not a good design, to write the knobs as string.
So i would refactor it to the following:
t.getKnob1 //if hardcoded or
t.getKnob(1)//if not hardcoded and i want to change the number on the fly
So in that case i have the same functionality but not only the
thing class, but more classes, classes for the knobs. But they are all anemic. so only data-classes, and having only a delegate-functionality to the parent, to
thing, because only the
thing can decide if the knob can be set to true or not. Its a anemic model here, i think. Maybe i also want to have some sub-knobs to the knob, and maybe a “light” to the knobs. But all is controlled by the
thing, because the knob-self cant decide that, if he is able to be set to true or not, also the logic if the light should be set on or not is in the
There is one more problem: I have a cyclic dependency between the
knob and the
thing. Cause the
thing want to set the state of the
knob and the
knob “must can” message the
thing about the state-change-wish, the user makes directly to the
Is that a good design?, If not (cyclic, anemic says it’s not), what i can do there better?
Maybe i also want to add there some observer. So a gui-element which presents one
knob have a direct listener on the particular
knob. Thats ok i think. But on the other side i want to have a network-listener, cause i want to send each change in the
thing over the network, then i think, having from the network listener on each
knobs isn’t a good idea, in that case i would only have one listener on the
thing, which streams all interessting informations about changes.
But how would you do this?
The gui-knob-listener could also became a problem. If i want to throw
thing away and want to install a new one, i have to unregister all listener on the
knobs, and install listener on the new
knobs (error-prune i guess?). So in that case i think it would also be easier if i dont work with the
knobs directly but with some
thing acting as a facade like in solution (1).
I modeled similar a few years ago. The
thing was a mixing-station. The knobs the parts on the mixer: slider, knobs, toggler, and so on. These are arranged in channel. But anyway if i put the logic into the knobs direclty, they must have access to each other one, to check if it is allowed to change the value. There were some user-retriction and some special slider (grouped-fader).
So an example: If a user changes one slider, the other one have to follow in some way (not always the same way). Manually i am allowed to change a slider from range 20-80, but if the controller decide, he can automatically change one slider to 110.
So how you would model that in a OO-way?.
It seems, that the object gets anemic, i get cyclic stuff in there, but i need a controll-unit, which do the decisions and the state-changes in the anemic objects.
Maybe i can model some logic into the anemic-objects (into the knobs, the slider, and so on), but anyway, i cant only work with the state in the anemic-object. I need more state, i need the state from other knobs. Also if i can set one knob to true, maybe there i must also set some other knobs to true. So here i don’t have any encapsulation anymore. So isnt it better to have that kind of logic not in the knob, but on a controller (a
- But is that still OO?
- How you would model that?
- Where you would put the logic? Into the knobs, into the controller, somewhere else?
- Is that ok expose the knobs in the sense of “public-interface”. So i dont hide the knobs in the controller. I expose that, because i see the knobs as part of
thing's public interface. Is that then ok? When you would hide that?
- Would you really…/or is there any case, where you would… access to the knobs with that string interface like in my solution 1?