Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I've only been programming for about a year, so bear with me. Everything I have done so far has been hard coded into my programs, but now I am faced with a situation where I would like to be able to make some of the code editable without having to publish a new solution and reinstall everytime a change needs to be made. One exact issue is I have a select case argument in my code, but every year this code needs to be added to. I don't need a complete code example or anything, I just need to be pointed in the right direction. Would this be done in a text, ini, xml, database, or some other file, or is there some sort of standard? Thank you in advance for any help on this!
Posted

This question is too broad to answer it in full. Basically, using data is much more than just avoiding hard-coding. It all depends on your requirements and different architectural option.

Of course, hard-coding of data is very, very bad. But what do you consider data? Your whole program can also be represented in the form of data handled by some other program.

The basic idea is that you cannot do an application which is absolutely universal, unless you model a whole computer in your program and let the users write their own. So, the solutions should be realistic and consider both functional requirements and the provision for flexibility in case of changing requirements. This way, you can understand what to make optional right away and what can rely on next release. In a general architecture, one should focus on identifying, where the knowledge is and where is the right method of expressing the knowledge. Some knowledge is represented in the source code, and this is ultimately unavoidable. This fundamental kind of architectural decisions is one of the difficult parts of work.

The options you've listed also depend on requirements. (However, you probably may forget obsolete INI and avoid plain text, but it should not be an absolutely strict rule.) You should consider them as a mere media for persisting data, not the data. To get better idea on what am I talking about, read about Data Contract: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

By the way, this is a best way to persist not very big volumes of data with minimal effort and maximum flexibility at the same time. Please see my past solution advocating this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

In this approach, you do not persist any separate data items, you persist the whole object graph of any complexity representing some data model.

That was about just the data. Now, let's come back on a more general level and talk about the knowledge.

You see, some knowledge is better to express in data, but some — in code.

Respectively, if you need non-monolithic architecture with more flexible possibilities for updates, you need to consider two ways: one is data persistence explain above, another one — pluggable architecture of the code with replaceable components usually called plug-ins. The plug-ins can even be reloadable.

I overview some of the approaches on my past solutions written in response to different questions. Please see:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
code generating using CodeDom[^],
Dynamically Load User Controls[^].

I won't be surprised that this is a bit over your head. I think that looking at the bigger picture is always useful. You can come back to it some day later.

—SA
 
Share this answer
 
v6
Comments
fjdiewornncalwe 13-Dec-11 18:24pm    
+5. Fantastic.
Sergey Alexandrovich Kryukov 13-Dec-11 19:07pm    
Thank you, Marcus.
This time, it was difficult. It's too hard to explain so complex issues to the beginner.
--SA
Nikil S 13-Dec-11 18:59pm    
Nice Answer, +5
Sergey Alexandrovich Kryukov 13-Dec-11 19:09pm    
Thank you, Nikil.
--SA
Simon_Whale 13-Dec-11 19:01pm    
+5
Hope you are on a high with SA's solution. While SA's solution gives you a bigger picture, for time being you can modify your code (select case logic etc) in such a way so as to read the varying data from a config file, xml etc. so that you won't need to publish and re-install again and again.

Try these CP articles and links,
Configuration Settings File for providing application configuration data[^]
http://vbnetsample.blogspot.com/2007/07/application-configuration-file.html[^]
http://visualbasic.about.com/od/usingvbnet/a/xmlconfig.htm[^]
XML configuration files made simple... at last![^]
 
Share this answer
 
v2
Comments
dropkickglobalism 17-Dec-11 16:37pm    
Thank you both for the responses, and yes, some of it did go a little over my head, but I think I just did a terrible job of explaining what I wanted to do. I don't want to make the entire/majority of the code universal or editable, I just want to place the data in the select case statement in a seperate file, so that that can be updated. I somehow have skipped working with databases, even though I have written some pretty complex socket programs (at least for my level). I haven't read through all of the listed material, so I may just find my answer. Thanks again!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900