V
V
vitaly_742020-05-05 07:47:09
Design patterns
vitaly_74, 2020-05-05 07:47:09

Chain of Responsibility and Decorators, how to pass data?

Good afternoon, I use 2 patterns in the action at the same time, decorators, for modifying the object, and a chain of responsibilities for modifying the algorithm, without changing the old code.
when analyzing the code, I saw that it was constantly crawling into the database for one record (for the same one), which, of course, I would like to avoid. Please advise how to transfer data between objects? I use AR.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2020-05-07
@vitaly_74

when analyzing the code, I saw that it was constantly crawling into the database for one record (for the same one), which, of course, I would like to avoid. Please advise how to transfer data between objects?
There is such an approach as UnitOfWork, in which objects are added from the persistence layer (storage layer), respectively, when there is a repeated call, the query does not go to the database ...
I use AR.
And here is the problem, since the AR module is a piece of database work, and not a thing separated from it. That is, she (the model) goes to the store, and not somewhere and someone goes after her ... The clearest example when the violation of SRP has a very painful effect.
Solution: you can put some provider on top of the model, which will persist the loaded objects, and it’s not the model that travels through the program, but the provider ... Then it will be possible to get the object from it, and if it doesn’t exist, load

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question