lundi 15 juillet 2019

Best design pattern for passing values through different classes

I am building an extensible system which have following requirements: 1. Each request will have 2 attributes: type, region 2. Based on the values of type and region, different configs will be selected 3. There are over 20+ classes which need to select configs based on type+region.

One method to implement this is to create a class with two fields: type and region. At the entry point, create an object of this class and pass it along to every function call. Based on the type+region value from that passed object, select appropriate config.

Instead of passing type+region object in every function, is there any elegant solution? Like extending an object dynamically? Or set an object at entry point and then reuse it by extending any particular class. I am new to system design and inheritance, so I cannot think of an elegant solution.

Aucun commentaire:

Enregistrer un commentaire