mercredi 21 mars 2018

Is this a design pattern? How to avoid a switch statement here

A picture is worth a thousand words hopefully

The bottom rectangle holds a bunch of child classes and a single base class. The top rectangle holds bits of logic

Each child class needs to run 1 or more bits of the top logic, there's no base class type commonality here

There are other 'top squares' of logic.

At present this is implemented using a switch statement (I know). The only alternative I can think of is a class with one method per piece of logic in and then each class can call the appropriate methods

The real life example is is for a bunch of reports and each report needs different gui elements on the page, but as I say there's no common behaviour that could be extracted into common base classes

enter image description here

Aucun commentaire:

Enregistrer un commentaire