I am coding a desktop project which will includes several classes, and will put many parameters in several database tables to make it easy to centralized maintenance after deployment. The problem is that these parameters might be used in these classes (it seems that this makes these classes has something been hard-coded and not generalized any more).
Should I try to avoid this happening? If so, how should I do it?
I come up with two possible solutions: 1) use function parameters to pass these parameters into the class when they are invoked (but there may be many parameters need to be passed in and several of them might have very non-generalized names. So this will still make the class not generalized). 2) use events to make all these parameters assigned only in the main Class. This will make all the class generalized and the main Class is the only place maintain all the parameters setup in the code. However, it is relatively hard to make this logic fulfilled in the code. Is this the right way to resolve this issue or is there any other better ways to resolve this issue?
Many thanks for your input in advance.
Wei
It is really hard to understand the exact problem without getting an illustrated example of some code, but I will generalize my response…
What you have described is the same thing I experienced a while back and typically it is the net result of making a function do to many things…
I am not sure if you are familiar with patterns / best practices but the single responsibility principle springs to mind straight away – WIKI Single Responsibility Principle
Have a relook at the methods and functions you are calling and see if there is a way that you can reduce them in complexity to the minimum parameters possible. Obviously with the root methods you may require a number of parameters – typically I use dependency injection and interfaces so that the function parameters do not get to long.
For example a method with the following…
Could be refactored to look like the following…
Hopefully this gives you a few ideas, obviously not a complete solution without a specific case given…