bắt nguồn từ bài viết http://blog.luuhoangnam.com/laravel/laravel-the-right-way.html
tác giả có nói đến command design pattern nhưng mô hình tối giản đi giống như thế này
<?php
interface Command
{
function execute();
}
class User
{
public function register()
{
echo('Hello world!!!');
}
}
class UserRegisterCommand implements Command
{
protected $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function execute()
{
$this->user->register();
}
}
class Handle
{
protected $command;
public function __construct(Command $command)
{
$this->command = $command;
}
public function handle()
{
$this->command->execute();
}
}
$u = new User();
$command = new UserRegisterCommand($u);
$handle = new Handle($command);
$handle->handle();
vậy tại sao dùng nó, làm thế nào để thêm nó vào đoạn code trên, thanks!