Most appropriate way to switch classes of active Apis in a system?

Asked

Viewed 16 times

0

Next, In this application there is an SMS sending module that has several different Apis, all follow the same basic standard, implement the required methods of the SMS interface, 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 to 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 that way there is no standardization, the API number is set manually, and every time you create a new class you need to add on the switch, which would be the most appropriate way to do this?

  • $sms_active is always the company number contained in the class name?

  • Yes, a number that comes from the database and I choose manually

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.