Hey i have question with a real word example. Its related to my two other, but not really answered questions here:
https://softwareengineering.stackexchange.com/questions/423392/no-trivial-god-class-refactoring
and
Let's say we have a switch with the methods switchOn(), switchOff(). The switch(es) are included in some other structure, for example a switch-bag, from where i can pull out the switches. This can be seen as a ready system.
Now i want to introduce the possibility of switching these switches on after a certain time automatically: A time switch
The time switch ueses now the "normal" switch. The normal switch doesn't have to know something about the time switch.
So but now the client can pull out the normal switch from the switch-bag and now he want also to get to the time-switch related to these normal switch, maybe to configure a new time.
And this is my question, how can the client get to the time-switch?
There are a few possibilites:
- I refactor the
normal switchclass to a third-class where thenormal-switchand thetime switchlives bundled in it. But for this, i break some other client code which still uses thenormal switch, but get now from the switch bag a "Combinator"-Class/Object out of it. - I don't change anything of the
normal switchclass. The client if he wants to get access to thetime switchhave to ask a Map whichtime switchis related to it. (I think this approach is classical a relation-programming style like a sql relationship database and its not anymore real object-oriented style) - I extend the
normal switch: Here i also have different options:- I change it to a big facade, which delegates the calls to the
normal-switchandtime switch(its similar to my first solution with the combinator, but here with an facade don't breaking some existing client code) - i extend the
normal switchletting the existingnormal switchcode untouched and introduce a component holder. Into this component holder i inject thetime switch. So i have these methods there:switchOn();switchOff();getComponent("timeSwitch"). But these approach feels like a entity-component system (https://medium.com/ingeniouslysimple/entities-components-and-systems-89c31464240d) but is that still object oriented programming?
- I change it to a big facade, which delegates the calls to the
i think the last solution is the best one, because its the most flexible.
But what do you think which approach is the best, maybe some approach i didnt mentionend here?
Edit: One more thing you must to know here: The time switch is one extension of the normal switch. One of many. So i want to add of course different more things XYZ switches/behavior extensions to the normal switch
Aucun commentaire:
Enregistrer un commentaire