mercredi 16 mai 2018

Design pattern to register handler (provider) to handle type of requests

I have scenario where I have collection of field object or its composition. Data of different field objects are stored in different data sources. I am looking for design pattern to register data providers for different field objects. I need flexibility to add new type of field objects and register handler to fetch data for those objects.

There are several pattern which I think can be used to solve some part of problem e.g. command pattern, observer pattern, chain of responsibility etc.

I would like the code to be

foreach ($compositions as $composition) {
   $data = $dataProviderRegistry->get($composition);
}

I would like DataProviderRegistry to select correct provider for composition object (or field object) registered to handle that type of object. I should be able to register new type of provider in registry to handle new types of field objects.

I am not sure how one or more type of design patterns can be applied to solve this specific problem.

Aucun commentaire:

Enregistrer un commentaire