mardi 17 juillet 2018

Replace switch with design pattern

Here is my class diagram enter image description here

I also have an enum for all the fields in the CameraControl base class.

In the implementation of the GetCommand() in the PelcoDCommand class, I have a switch statement that returns the command based on the enum.

The switch statement consists of 18 case (one for each enum). For example,

public override byte[] GetCommand(PelcoDCommands command)
{
  switch(command)
  {
    case PelcoDCommands.Stop:
      return Stop;
    case PelcoDCommands.PanUp:
      return PanUp;
    case PelcoDCommands.PanDown:
      return PanDown;
                .........
  }
}

Can anyone point me to a proper pattern to replace the switch statement? And if anyone has a guide to a better implementation of the classes?

Aucun commentaire:

Enregistrer un commentaire