在包装照明/容器中 我想使用观察者。
但是一个界面如何在一个类中绑定两个不同的实例?
我可以使用Closure吗?我该如何使用它?
class User extends Controller {
public function save(Subject $user, Observer $department, Observer $permission)
{
$user->attach($department);
$user->attach($permission);
$user->doSomething();
}
}
interface Observer {
function bind($object, Subject $subject);
}
class DepartmentService implements Observer
{
function bind($object, Subject $subject)
{
}
}
class PermissionService implements Observer
{
function bind($object, Subject $subject)
{
}
}
interface Subject
{
function attach(Observer $observer);
function detach(Observer $observer);
function notify($user);
}
想想你的答案!