Soon, I decided to go for Dependency Injection technology for the new PHP application that I am going to write.
However, I'm not quite sure that I understand this enough. My problem is that baseClass is dependent on different elements, while many different classes will have to extend it. For instance:
namespace system;
class baseClass
{
protected $logger;
protected $filter;
protected $database;
protected $session;
public function __construct(LoggerInterface $logger, filterInterface $filter, databaseInterface $database, sessionInterface $session)
{
$this->logger = $logger;
$this->filter = $filter;
$this->database = $database;
$this->session = $session;
}
}
Most classes will require a log, filter, etc. to complete its tasks: the filter class, for example, handles the screening / verification that I need throughout the project.
, , () baseClass, ( , , , , ) , .
, , "", :
$car = new Car($color,$amountOfWheels);
:
$car = new Car($logger, $filter, $database, $session, $color, $amountOfWheels);
, , , DI.
, - factory , factory .?