I’m just wondering if you have an application where you define a class that defines some user configurable settings (from an xml file, or a GUI), should you design it so that it follows SOLID as much as possible like the rest of the application?
More specifically, how do you change the available settings without violating the Open Closed Principle?
Because I’m having trouble picturing this. I can see the addition of settings you can extend the class, but with the removal of settings, or change of a setting there would be no way to modify the configuration class so that it follows SOLID. Or is it possible somehow?
I can also imagine trickle down effect from those settings changes, that require classes that depend on them to be modified as well.
6
I think the problem that you are experiencing is not with the Open / Closed principle, but more so with the Interface Segregation Principle.
If you treat configuration as a dependency of the classes that use it, you would want that configuration interface to have method / properties that have high cohesion. Therefore a new configuration variable would have a relatively small impact on the system.
Having such an interface allows you to do do unit-testing for different configurations, and allow you to change how those configuration values are derived without significant changes to your application (store in database instead of xml).
public interface IBlogConfiguration
{
public int GetNumberOfPostsPerPage();
}
public interface ICommentsConfiguration
{
public bool AreCommentsAllowed();
public bool CanCommentsBeNested();
}
public class WebConfigConfiguration : IBlogConfiguration, ICommentsConfiguration
{
// implementation of both those interfaces
}