• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

INI file and pattern !/ Best design

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am rewriting a legacy application that writes configuration options as an INI file.
The INI file has got to stay (so, please do not talk about property files or XML files)
Now : the particularities :
1) The file structure changes quite often, from one version to the other
2) I've got to maintain file version as all users are not on the same version.
The aim of the rewrite operation is :
- to make it easy to manage upgrades,
- to make easy to manage versions,
- to make it easy to add/remove items to the INI file
First thought of Visitor pattern, but this does not fullfil my requierement.
Can anyone thing of a better design (or design pattern ) ?
Regards,
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you give us any more information about the structure and scope of these "ini" files? (I'm not worried much about syntax, just the complexity of the possible data.)
Are they basically name/value pairs (like properties files). Are they hierarchical (like XML, LDAP or Windows Registry), are they tabular (like CSV or database tables), are they "chunked" (like Windows INI files with delimited sections, each of which is a set of name/value pairs) etc?
Also very importantly, does the file data contain any explicit version information, or does your code have to deduce if from the contents?
 
raphael Bereh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a basic Key = Value file with data organised in headers.
The file does contain an explicit version number to ease the upgrade process, but it is still quite tricky to know ( and understand) how upgrades are done.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about a handler for each version, all handlers convert the version-specific quirks into a common format? Determine the version, get a reader / handler from a factory and let it finish the job.

This is pretty much Strategy if you want to scan the pattern books for more considerations.
 
raphael Bereh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much James,
A quick look a the Applicability of Strategy pattern tells me that this is what I need.
Thanks again.
Regards,
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic