A
A
Alexander2020-07-14 03:56:20
PHP
Alexander, 2020-07-14 03:56:20

Law of Demeter and Doctrine?

Hello.
I have a question regarding the connectivity of modules in a web project developed in PHP.
Doctrine is used as ORM.

If the modules should not know about each other (they have limited information available through services), then what about the situation when complex selections with filters, aggregation, affecting the entities of other modules should be made in some modules?

Doctrine is good at managing relational relationships between entities. And if the modules communicate with each other only through services, and without describing relationships through Doctrine, then this will seriously affect performance.

How then to be?
Thanks in advance for your replies!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adamos, 2020-07-14
@gophp

You can consider a scheme in which the module itself provides others with the opportunity to use its data. In this case, an external interface with a method that completes the external request in accordance with the filters that are passed to the function. As well as a method that returns a description of possible filters - so that the question of what can be requested from the module is decided not outside it, but in itself. So the external module will not know anything about the one being used, but at the same time it will be able to use its data.

M
Maksim Fedorov, 2020-07-14
@Maksclub

then what about the situation when complex selections with filters, aggregation, affecting the entities of other modules should be made in some modules?

To solve problems in another module/domain, there is no need to have the entities of another project/module/bundle. Example in the delivery module
  • you do not need to know EVERYTHING about the product and the logic of its collection, you need to know the size and name
  • in this module, you do not need to know everything about the order - only the address, time. The history of its processing and statuses (all of this is in the Order aggregate/entity), the impact of promotions and promotions - you don’t need to know this, but it exists!... by transferring the entity somewhere, you transfer knowledge and connect different modules
  • you do not need to know much about the user, except for the phone number, name and address

Therefore, you can select from the database only the necessary data for a specific module. A sort of projection according to needs. This is the observance of the law of Demeter - you do not climb into another module, you climb into the infrastructure (universe), which will give you exactly the knowledge and state that you need. That is, for your data.. Moreover, this knowledge can be collected in various ways and not necessarily from relations, but can be aggregated in NoSQL form, for example.
Krch for one module, you get some projections / data that in this module you won’t even say - where they came from, because there is no such knowledge - from the persistence layer and that's it ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question