M
M
microf2019-06-13 14:32:47
OOP
microf, 2019-06-13 14:32:47

How to design an aggregator?

Good afternoon. It is necessary to assign a rating to the organization.

public function __construct(
            OrganizationID $id,
            Name $name,
            array $phones,
            array $addresses,
           Specialization $specialization
    ) { }

The initial rating can be assigned when saving the organization and depends on the Specialization (this is the specialization of the organization, the more the better). How to organize it?
To do it in service at creation?
public function create(OrganizationRepositoryInterface $repository, OrganizationRatingService $rating): void
    { 
    $organization = new Organization(
     ... 
    $this->repository = add($organization)
    $rating (Вот что сюда передать, только специализации? а как потом сохранить?
)
}

Whether to consider a rating at once in Entity at creation? Type
public function __construct(
            OrganizationID $id,
            Name $name,
            array $phones,
            array $addresses,
           Specialization $specialization,
           OrganizationRatingService $rating
    ) {
    $rating->setRating($specialization);
 }

How right? Setting a rating is a business rule. Like then it should be in essence. On the other hand, the rating service itself is a lot of different options and littering the essence is somehow not very good.
Where to count it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Romashkan, 2019-06-13
@microf

1. Make a separate entity - Organization Rating, and have a common ID with the organization. There is already a static constructor that initializes the rating by the number of specializations.
Judging by the description, neither the name, nor the phone numbers, nor the addresses are needed to calculate the rating, which means that it makes no sense to put it in the same entity.
I think the best option.
2. The entity can, if desired, be put in the field at the root of the aggregate.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question