This commit is contained in:
Dominik Liebler
2013-09-13 12:00:39 +02:00
parent 2d3fc40a39
commit 644d9cbd49
12 changed files with 86 additions and 78 deletions

View File

@@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\NullObject;
/**
@@ -11,20 +7,28 @@ namespace DesignPatterns\NullObject;
*/
class Service
{
/**
* @var LoggerInterface
*/
protected $logger;
// we inject the logger in ctor and it is mandatory
/**
* we inject the logger in ctor and it is mandatory
*
* @param LoggerInterface $log
*/
public function __construct(LoggerInterface $log)
{
$this->logger = $log;
}
/**
* do something ...
*/
public function doSomething()
{
// no more check "if (!is_null($this->logger))..." with the NullObject pattern
$this->logger->log('We are in ' . __METHOD__);
// something to do...
}
}
}