Suppose you need to check some condition at multiple places in code. For ex. we have a configurable element in config file called System.
So if System = “A” do some work/show some screen else do other stuff
I dont think its a good idea to check at many places the same condition. what should be the approach ?
Thanks.
Make your configuration more object-oriented, instead of just key/value pairs – so your condition would become
where
IsSomeConditionwould wrap the underlying details.Alternatively, you could potentially use polymorphism with virtual calls to do the right thing – create the appropriate instance (once) based on the configuration, and let polymorphism do the rest. It’s very hard to say without knowing more details of what you’re trying to do.