jeudi 25 janvier 2018

Refactor IF ... ELSE desing

I have legacy code and my task to refactor it.

  1. There is base class (ie vehicle)
  2. it's heirs (car, bus, motorcycle and so on)
  3. Service that has to choose and greate instance appropriate heir by parameter

So I've something like this:

...

   if (param == "car")
        result = new Car();
    else if (sectionType == "bus")
        result = new Bus();
    else if (sectionType == "motorcycle")
        result = new Motorcycle();

...

I think that code isn't productive and supported.

Q: My aim is founding out the better design solution.

Thx in advance

Aucun commentaire:

Enregistrer un commentaire