Home > Net >  What do you use to store mutable objects in a file?
What do you use to store mutable objects in a file?

Time:02-10

Suppose you write a program for a customer who doesn't know anything about programming and will never take a look at your code.

This program could, for example, analyze data from weather stations. Now the program should not collect and evaluate the data of ALL weather stations in the world at every run.

The user should now enter in a file, which stations on which continents and in which countries he wants to have evaluated. It should be a KeyValuePair, which is in a file. It should be very easy for the user to edit the file, it must be easy to read/maintain. Here is a small example:

---- Enter here from which continents/countries you want to have the data ----

"Asia" ; "China" , "Japan" , "South Korea" "Europe" ; "United Kingdom" , "France"

I hope you know what I want. How would you do it? I tried with a config file, but I don't know if this is the right way.

By the way, I write in C#, if that is important

CodePudding user response:

If your client knows nothing, a simple list format would do. But since you said it should be a key-value type file, you could use JSON which is pretty human-editable at this level of complexity. If you want a simpler-to-implemet approach, you can use the c# XMLSerializer with a KeyValuePair class.

CodePudding user response:

Well this is typical "business configuration" for the application.

You can enable the user to amend and store this in multiple ways. There are a couple of things you need to decide:

  1. How to store the data This could be in a file of some kind (config, XML, JSON, YAML), or a Database

  2. How to allow the user to amend the data

For your case, I think storing in a config file is easier. These days JSON is very popular method of serialising data and has the advantage that it is human-readable.

Then you can decide if you want the user to be able to amend this file directly themselves, or if you will provide an application / screens to allow them to do that. The advantage of the latter is that you can sanitise the data input.

CodePudding user response:

Use a file as database it's a good idea for simple applications. If your customer it's not comfortable with programming you can use an excel/csv file instead a json/xml and help him with the grid template (header, columns, rows...).

  • Related