This is how our functional code is structured.
Functional code calls ConfigAdapter
which can fetch the configurations from any other store.
Now with the change in the requirements and to decouple the configurations, we created a new class called ABCConfigAdapter
(Consider "ABC" to be some business specific term).
ABCConfigAdapter
has same methods as ConfigAdapter
but now has one more extra parameter to be passed called ABCConfigAttributes
. ABCConfigAttributes
determines the way in which we fetch the configuration for "ABC" business use-case.
Since ConfigAdapter
was used where ever the functional code requires some configuration, now the changes are huge. That is not the actual problem, the problem here is how to pass ABCConfigAttributes
as the object for ABCConfigAdapter
?
Here are some of the ways of doing it:
- Since the data in
ABCConfigAttributes
is specific to a particular thread, we thought of storingABCConfigAttributes
inThreadLocal
and where-ever we want to callABCConfigAdapter
we fetchABCConfigAttributes
from ThreadLocal and pass it on toABCConfigAdapter
- Make changes to pass
ABCConfigAttributes
from the top class to the hierarchy everywhere!
Obviously #2 is more costly because it has lot of intrusive changes. I want to understand whether is it a good practice to store Business objects in ThreadLocal (as described in #1) in these type of use-cases?