lundi 5 juin 2017

Strategy pattern with different method signatures

Using the strategy pattern, how can treat different exectute methods differently in terms of them having different parameters?

3 example strategies

public function execute(string $param1, string $param2)
{
    // Do something specific to this method
    //


    // Do some generic things across all strategies
    //
}

public function execute(string $param1)
{
    // Do something specific to this method
    //


    // Do some generic things across all strategies
    //
}


public function execute()
{
    // Do something specific to this method
    //


    // Do some generic things across all strategies
}

The all do something very specific but require different parameters for this, then they do something generic that every strategy will do.

Aucun commentaire:

Enregistrer un commentaire