Use Case for Modifying Configuration Files.

101 views
Skip to first unread message

James Carl Necio

unread,
Feb 25, 2014, 5:54:15 AM2/25/14
to clean-code...@googlegroups.com
Hi Everyone,

Once again I have came upon something unclear and in need of professional help. I'm part of a team that is working on a new system that is integrated with another system, and our new system has a feature that configures the configuration for that other system. The other system's configuration files seems to be updated quite frequently and every time they update it, we need to edit our UI, the logic in saving the configuration. The code just gets bigger and it seems to be a major violation of the Open and Close principle.

My Question is Do I need to segregate each and every configuration settings in use cases like one for setUserName, setPassword etc.
PS. The configuration file is just one file and cannot be split into multiple ones and is composed of some key=value configuration parameters

Uncle Bob

unread,
Feb 27, 2014, 2:02:02 PM2/27/14
to clean-code...@googlegroups.com
The problem is that the UI code is coupled to the schema of the configuration.  Every time the configuration schema changes, the UI code has to change.  The trick is to decouple these two things by inserting an abstraction between them.

In this case the abstraction is probably best written as a grammar (a text file).  The grammar defines the configuration schema and generates the code for both the UI and the configuration data structure.  So when the configuration schema changes, you can make the change in one place, and then regenerate the code.

James Carl Necio

unread,
Mar 4, 2014, 8:36:06 PM3/4/14
to clean-code...@googlegroups.com
Thank you very much Uncle Bob for that reply. Correct me if I'm wrong but you mean that I should make one of those Finite State Automata to tackle with my dilemma so that I don't have to do those UIs and data structures manually but just update my grammar file. If only I know how to do such a thing, That would be great. :)

witali mik

unread,
Mar 5, 2014, 3:28:34 AM3/5/14
to clean-code...@googlegroups.com
Personally in this case, i would treat the Config as an Entity, so the Point, that this is an Configurationfile, i would just ignore.


You will have an interactor "DisplayConfiguration" this interactor requires ConfigRepository. the ConfigRepository will be in your case "FileConfigRepository" which loads the file and use DataMapper to convert the file into an object. at the end, your "DisplayConfiguration" return as Response just a simple array of key=>values. so inside your template, you just have to iterate over the array and create inputfields filled with values.

after this, you create a "ModifyConfiguration" interactor, it requires the FileConfigRepository as well. the interactor requires an array of key => value pairs. so inside the interactor, you iterate over they array in fill your entity. then you put the entity back into repository.

In PHP For example, its not a big deal to convert an array into an object and use array keys for object setters/getters.

what i described, might not working in other languages(i dont know, since i really have a clue just about PHP)
Reply all
Reply to author
Forward
0 new messages