Answer the question
In order to leave comments, you need to log in
Correct use of a constructor?
I write new objects to the properties, and use them in the heirs. Doesn't this violate OOP principles?
public function __construct()
{
$this->layout = new View('/layouts/single');
$this->model = new Models\Catalog;
$this->widgets = new Widgets;
}
Answer the question
In order to leave comments, you need to log in
It's okay until you start testing, then you hit SOLID.
public function __construct(ViewInterface $View, CatalogInterface $Catalog,WidgetsInterface $Widgets)
{
$this->layout = $View;
$this->model = $Catalog;
$this->widgets = $Widgets;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question