mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-01 12:40:11 +02:00
PHP7 Visitor
This commit is contained in:
@@ -2,29 +2,25 @@
|
||||
|
||||
namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
/**
|
||||
* An example of a Visitor: Group.
|
||||
*/
|
||||
class Group extends Role
|
||||
class Group implements Role
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = (string) $name;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Group: '.$this->name;
|
||||
return sprintf('Group: %s', $this->name);
|
||||
}
|
||||
|
||||
public function accept(RoleVisitorInterface $visitor)
|
||||
{
|
||||
$visitor->visitGroup($this);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user