小编Nux*_*win的帖子

DDD - 聚合 - 真的应该避免使用吸气剂吗?

早上好,

我已经读过很多次了,在 AR 中应该避免使用 setter 和 getter。虽然我可以理解使用 setter 的原因,但当它们显然是业务的一部分时,我对 getter 有点不同意。

让我们想象以下用户AR:

namespace vendor\Domain\Model;

class User
{
    private $userId;
    private $username;
    private $password;
    private $email;

    static public register(...): User { ... } // Ubiquitous Language
    public function unregister(...) { ... } // Ubiquitous Language
    public function changePassword(...) { ... } // Ubiquitous Language
    public function changeEmail(...) { ... } // Ubiquitous Language
    public function getAggregateId(): UserId { ... } // A getter
    public function getUsername(): UserName { ... …
Run Code Online (Sandbox Code Playgroud)

php getter domain-driven-design aggregate ddd-repositories

4
推荐指数
1
解决办法
624
查看次数

DTO可以引用领域模型的VO吗?

问题

数据传输对象(DTO)可以引用域模型的值对象(VO)吗?

语境

在我的域中,我有一个导入器,它从集合中导入聚合。该集合由进口商依赖的收集器构建的 DTO 组成。由于导入器和收集器都是我的域的服务(接口),DTO 是否可以引用域值对象,或者我应该坚持使用原语并仅在处理集合(聚合的构建)时将它们转换为值对象?

收集器实现,其中构建了由域模型中的值对象组成的 DTO

<?php
/**
 * i-MSCP Patcher plugin
 *
 * @author        Laurent Declercq <l.declercq@nuxwin.com>
 * @copyright (C) 2019 Laurent Declercq <l.declercq@nuxwin.com>
 * @license       i-MSCP License <https://www.i-mscp.net/license-agreement.html>
 */

/**
 * @noinspection
 * PhpUnhandledExceptionInspection
 * PhpDocMissingThrowsInspection
 */

declare(strict_types=1);

namespace iMSCP\Plugin\Patcher\Infrastructure\Domain\Service\Component\Importer;

use iMSCP\Plugin\Patcher\Domain\Model\Component\ComponentBuild;
use iMSCP\Plugin\Patcher\Domain\Model\Component\ComponentName;
use iMSCP\Plugin\Patcher\Domain\Model\Component\ComponentVersion;
use iMSCP\Plugin\Patcher\Domain\Service\Component\Importer\ComponentCollector;
use iMSCP\Plugin\Patcher\Domain\Service\Component\Importer\DTO\ComponentDTO;
use iMSCP\Plugin\Patcher\Domain\Service\Component\Importer\DTO\ComponentDTOCollection;
use iMSCP_Config_Handler_File as MergedConfig;
use iMSCP_Plugin_Manager as PluginManager;
use RuntimeException;
use Throwable;

/**
 * Class DefaultComponentCollector
 * @package iMSCP\Plugin\Patcher\Infrastructure\Domain\Service\Component\Importer
 */
class DefaultComponentCollector implements …
Run Code Online (Sandbox Code Playgroud)

collections domain-driven-design dto value-objects

2
推荐指数
1
解决办法
399
查看次数