带有调用存储库的方法的 OOP 模式


OOP Pattern with methods calling Repositories

我有一个类DashboardService(在symfony2中定义为服务),我用它来调用一些方法来从一些存储库获取结果(只是查询)并显示数据。

class DashboardService {
/**
 * @var EntityManager 
 */
private $em;
public function __construct(EntityManager $em) {
    $this->em = $em;
}
public function getTotalActiveCampaignsByMonth($month) {
    $campaigns = $this->em->getRepository("WMAdminBundle:Campaign")->countAllActiveCampaignsByMonth($month);
    return $campaigns;
}
public function getTotalContactsByMonth($month) {
    $contacts = $this->em->getRepository("WMAdminBundle:Contact")->countAllContactsSentByMonth($month);
    return $contacts;
}
public function getTotalCAByMonth($month) {
    $ca = $this->em->getRepository("WMAdminBundle:ContactCampaign")->getAllCAByMonth($month);
    return $ca;
}
public function getTop10RentabilityCampaigns() {
    $campaigns = $this->em->getRepository("WMAdminBundle:Campaign")->findAllTop10Rentability();
    return $campaigns;
}
public function getTop10ContactCampaigns() {
    $campaigns = $this->em->getRepository("WMAdminBundle:Campaign")->findAllTop10Contacts();
    return $campaigns;
}
}

这个类是 OOP 模式还是什么?

就像典型的分层架构中的基本应用程序服务。

应用程序服务:外部消费者用来与您的系统通信(想想 Web 服务)。如果使用者需要访问 CRUD 操作,他们将在此处公开。