Disclaimer: I'm using C# for code examples. But I guess they should be readable/understandable for everyone. If they are not: please leave a comment.

Okay I have a Client-Server application. The server can be extended with Agents. An agent can be used to distribute loads.

An Agent should have some static variables like ID etc. All of these values will be self-generated (ex.: ID = Guid.NewGuid(). The ID should be once set and always be the same. Even if you restart the Agent.

My first thought was I want to have some kind of Config class which contains these variables.

class Config 
    public Guid ID { get; private set; }
    // ...

Okay when an Agent starts it should check IsConfigurationInitialized. If its not, initialize it.

I thought it would be an neat idea not to care about the initalization of the configuration. So the configuration itself check in the constructor if it needs to be initalized. So my main path of the application just do something like Config config = new Config();

But for some reason I feel like this is a bad idea since the class is just a variable holder.

To my question:
Does the above given example break the SOC or any other design principle?

  • Every design breaks some "design principle". Even the definition of a "concern" in the phrase "separation of concerns" is subjective. Ask youself, what are the alternatives, and why are they better? I always tell people to choose the solution that requires the least amount of code, when it is an unimportant part of the application (which this appears to be). – Frank Hileman Mar 2 '15 at 16:33

That design seem to violate SRP since your Config (which is a config, just a configuration holder) will know how to generate configuration for each specific agent).

I think an Agent should create Config instance, passing to it it's name (which is used to deduce configuration file path from it) and the callback, which should returns Agent's initial configuration.

Config checks for configuration file existence when created / initialized (somehow I do not like to perform heavy tasks in constructors and tend to create initialize() methods for those). If it exists, it just loads config from it. If it does not, it executes callback, receives initial configuration from Agent and saves it to the file for later use.

This way your Agent and Config are more or less separated from each other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.