Centralizing the configuration for easier management
Creating tons of classes is very object-oriented and follows the single responsibility principle, among others. However, dividing responsibilities into programming concerns does not always lead to the easiest code to understand because it creates a lot of classes and files, often spread across multiple layers.
An alternative is to regroup the initialization and validation with the options class itself, shifting the multiple responsibilities to a single one: an end-to-end options class management.
The name of the project in the source code is CentralizingConfiguration.
In this example, we explore the ProxyOptions class, which carries the name of the service and the time the proxy service should cache items in seconds. We want to set a default value for the CacheTimeInSeconds property and validate that the Name property is not empty.
On the other hand, we don’t want the consumer of that class to...