Answer the question
In order to leave comments, you need to log in
How to work with a complex entity if I just need to display the data?
Good day.
There is a complex Aggregate Root. The complexity of it lies in its creation, since the data for this is taken from various sources.
The task is simply to display a list of such entities.
Does it make sense to build such a complex object every time if out of all the available fields I need to use just a couple + some behavior that also depends on multiple fields?
And in general, how to work with such complex entities when the task is very simple?
Answer the question
In order to leave comments, you need to log in
Use lazy loading of data:
class Test
{
protected $abc;
public function getAbc()
{
if (!isset($this->abc)) {
$this->abc = new Abc;
}
return $this->abc;
}
}
Through the nodes of the desired graph of connections from various fields of the same type: one property is one graph.
Pull the necessary nodes by property1 and get a list1 of related objects.
Then, pull others by property2 and get a list2 of related objects as well.
Then do the intersection of list1 and list2.
Result: a list of objects united by selection criteria for property1 and property2.
And what prevents you from creating a separate method for building a simpler entity for the list? You can not only simplify the builder, but also create a separate entity with its own logic based on the same table and use it depending on the task.
Z.Y. I didn’t go deep into DDD, so I can talk nonsense.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question