Best way to switch active API classes in a system?

0

Next, In this application there is a Sms send module that has several different APIs, all follow the same basic pattern, implement the required Sms interface methods, something like this:

interface Sms {

    function setNumber();

    function setMessage();

    function Send();
}

class smsEmpresa1 implements Sms () {
    ...
}

class smsEmpresa2 implements Sms () {
    ...
}

And in the controller, the active API is called through a value saved in the database:

switch ($sms_ativo) {

        case '1':
            $sms = new smsEmpresa1;
            break;

            case '2':
            $sms = new smsEmpresa2;
            break;
    }

    $sms->setNumber('xxxx');
    $sms->setMessage('yyyy');
    $sms->Send();

But in this way there is no standardization, the API number is defined manually, and every time a new class is created it is necessary to add on the switch, what would be the best way to do this?

    
asked by anonymous 25.05.2018 / 17:53

0 answers