我目前正在重构一个中型项目,并遇到以下情况。 (用于简化示例的伪代码位)
class PostRepository {
}
class PostManager {
/**
* @var PostRepository
*/
private $repository;
public function __construct(PostRepository $repository)
{
$this->repository = $repository;
}
}
class DeletePostCommand {
/**
* @var PostManager
*/
private $postManager;
/**
* @var PostRepository
*/
private $postRepository;
public function __construct(PostManager $postManager, PostRepository $postRepository)
{
$this->postManager = $postManager;
$this->postRepository = $postRepository;
}
}
这应该重构吗?或者这样好吗?
或者我应该在getPostRepository
课程中创建PostManager
函数?这不会违反单一责任原则吗?