mercredi 9 novembre 2016

Optional abstract method

I currently have an abstract class which i am extending to other controllers. I have a abstract function within the abstract class which takes the value and places it in the __construct.

abstract class Controller extends BaseController {
    abstract public function something();

    public function __construct(Request $request) {
        if (!is_null($this->something())){
            $this->global_constructor_usse = $this->something();
        }
    }
}

My problem is that on controllers that dont require this abstract function, i am having to place in the empty function.

class ControllerExample extends Controller {
  public function something(){
      return 'somethinghere';
  }
}

Is there anyway to making the abstract function optional or have a default value?

class EmptyControllerExample extends Controller {
  public function something(){}
}

Or what would be the best method of going about this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire