lundi 9 janvier 2017

Is there a design pattern for methods methods to be presents depend on settings? (not interface)

given this class:

class Environment
{
    private array $environments = array('dev', 'prod');
    private $env = '';

    public function setEnv_dev()
    {
        $this->env = 'dev';
    }

    public function setEnv_prod()
    {
        $this->env = 'prod';
    }
}

adding setEnv_*-es is good, as long as a new environment (e.g. test) enters and we forget it. It will only cause errors when we try to run it. Is there a way to make fatal error instead?

Aucun commentaire:

Enregistrer un commentaire