Joy*_*yce 2 php design-patterns repository-pattern laravel laravel-4
我正在尝试使用Laravel实现存储库模式.我可以理解使用接口来抽象数据存储的好处.
但是接口中定义的方法返回的对象呢?他们是否也应该在某种抽象类中定义?
例如:
class UserRepository implements UserInterface {
protected $user;
public function __construct(Model $user)
{
$this->user = $user;
}
public function find($userId)
{
return $this->user->find($userId);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中执行此操作:
$user = UserRepository::find(1);
$user->name
Run Code Online (Sandbox Code Playgroud)
我打破了设计模式吗?
| 归档时间: |
|
| 查看次数: |
933 次 |
| 最近记录: |