Answer the question
In order to leave comments, you need to log in
How to organize a factory?
The application has the following structure:
Component\service\CatalogProductRepository
Component\domain\CatalogProductRepositoryInterface
Component\cache\CatalogProductRepositoryCache
There was a problem using this component. At the moment, for initialization, you need to execute:
$baseModel = new Component\service\CatalogProductRepository;
$cache = new Component\Cache;
$model = new Component\cache\CatalogProductRepositoryCache($baseModel, $cache);
$model = CatalogProductRepositoryFactory::create(true); // create($useCache = false)
$model = Factory::create('CatalogProductRepository', true); // create($model, $useCache = false)
Answer the question
In order to leave comments, you need to log in
Maybe well him? Really? Try to read this code to someone, it is not readable. I have no idea why you chose to name the product repository CatalogProductRepository. Or why do you need a factory. Well and still - what for you all hands. And what is true.
Both options, as for me, are replete with unnecessary complexity, non-obvious, etc. etc.
I suggest you arm yourself with DependencyInjection. The implementation of this is in any self-respecting framework. And get rid of obscure and implicit constants.
My "idea" was just to use a decorator to implement the caching logic. The essence of the idea is simple - to add caching, you do not need to edit anything either in the logic using the repository or in the repository itself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question