mercredi 2 mai 2018

How to eliminate switch-case in cod?

Lets say I have a switch case that looks something like this: (just an example)

switch(Type) {
    case MSSQL:   /
      Connector = new MSSQLCOnnector(
              args);
      break;
    case MYSQL:
      Connector = new MYSQLConnector(
              different_args);
      break;
    case ORACLE:
      databaseConnector = new OracleConnector(
              again_different_args);
      break;
      default:
          break;
  }

Since Switch-case violates OCP, is there a way to eliminate it, and use something else in code?

Thank you.

Aucun commentaire:

Enregistrer un commentaire