Let's say I got a series of services that are handled by a central hub, part of the behavior of the application is controlled by a series of settings that are stored on a file. Right now when I get a request and create the handler for it I inject an ApplicationSettings object that would allow the object to access the setting that matter to it; of course I could provide these values on the constructor, but then some constructors would accept a long list of strings, which does not seem very readable to me. Would it make sense to create an interface for each handler to provide access only the settings that are of handler's concern?
1 Answer
Would it make sense to create an interface for each handler to provide access only the settings that are of handler's concern
I would generally say yes. If each object takes a generic config then that makes life very easy for you (the programmer), but the user/client is only going to discover missing configuration during runtime. I would rather have the construction parameters to be explicit.
If you have a huge number of these params, perhaps your object is doing more than it should be? Can you package related config items into smaller objects encapsulating a configuration for a subsystem?
I could provide these values on the constructor, but then some constructors would accept a long list of strings, which does not seem very readable to me
Another option here is to make use of the builder pattern, which will simplify the constructor.
-
Settings would be on a single file, my idea would be that I use the same object implementing all the interfaces. Regarding the big number of parameters I'm talking about 4-5 parameter tops but it seems to me tha's too many.– ZalomonCommented Jun 10, 2016 at 11:24
-