0

I'm working on a simple application for a game in Java that allows a user to record whether they have collected a given item and how much experience it contains. This will work for multiple item types (weapons, armor) and each will have its own tab with a list of all items that qualify under it. Making changes as new types are added is not such a big deal (if a clothing slot is added, for instance), but new items are added to the game all the time in biweekly patches, and I'm not sure what the traditional/customary way to make sure the application is user-extensible without requiring me to would be.

Whether that would be adding a configuration menu that allows users to add news items (new rows to the local SQLite database) or a text file with something similar, but I'm certain there's a well-accepted way to do this that I'm not aware of. I'm new to databases and ignorant of the solution, so what's the professional/futureproof way to do this?

Jsess
  • 71
  • 1
  • 6
  • Do you mean new items or new types of items? – Euphoric Mar 23 '14 at 07:01
  • 2
    Can you give an example for where you see problems arising? Adding items to a database row from time to time is nothing which implies a loss in maintainability. And if you mean how to handle database schema changes over time, I recommend this former question: http://programmers.stackexchange.com/questions/202541/achieving-zero-downtime-deployment – Doc Brown Mar 23 '14 at 07:40
  • You're right, adding data won't cause me problems on the coding end - it's just new lines for the table. The problem is that I don't want to have to go back and handle new rows every time a new items is released every other week - I want this single release to stand on its own unless new categories of items are released in new slots (where I can go in and add a brand new tab/handling for this, as this will be far more complex and may need new fields that previous items didn't.) Thank you for the former question, checking it out now! – Jsess Mar 23 '14 at 13:52

1 Answers1

1

Three points.

  1. You need your code to be stable. Occasionally you will have to change it to add new item types or features, but it will always have to be backward compatible.

  2. So new items, and as far as possible new types of items will be added in data, not code. It matters not a bit whether you use a database, text file, XML, JSON or binary blobs, because...

  3. You need to provide a user interface for updating the data. When new things have to be added, the user goes to a form or screen or data entry device that allows new stuff to be added and checked for validity. That is how it's done (or should be done).

  4. When you do need to add new functionality, as well as backward compatibility you need to upgrade/migrate existing databases. Users don't like to lose what their work just for your convenience.

david.pfx
  • 8,105
  • 2
  • 21
  • 44
  • Yeah, that's correct - new items that are added will be in the form of data, not code. It does seem that allowing the user a means to enter new items would solve this problem. What if a new type of item is added (IE socks) and I need to go back and create this new category/items? If the user were to replace their current database file with the new one that has initialized entries for the new item types, they'd lose all their old data. I'm assuming that the best way to handle this would be to check to see if records for those exist and initialize if they don't for backwards compatibility? – Jsess Mar 23 '14 at 13:49
  • @Jsess: SOP. Maintain code compatibility, upgrade existing databases, migration. The usual stuff. See edit. – david.pfx Mar 24 '14 at 00:31
  • @jsess you've tagged your question java and sqlite, which suggests to me that you are more likely than not working on android. If so, android has a framework for data migration that you might be able to use. Look for samples using the onUpgrade method of SQLiteOpenHelper, which ought to give you some idea how this is usually done. – Jules Nov 19 '14 at 07:47