How to properly structure a collection of immutable constants

I’m in the design stages of a program that based upon input received, would select a particular category, and action within that category. The category, the action within in, and the value(s) related to that action are all immutable values, along with the relationship between category and action.

Normally I’d just assign it all into a multidimensional array or collection, but that strikes me as both messy and unnecessarily complex to search and sort. Constants don’t allow me the luxury of defining relationships between them (aka you can’t have constant A bound to subConstant B for example), and being a desktop app, having a user setting up a database server isn’t appealing. Was thinking of having everything in xml files, but core rules of the application isn’t appealing due to being able to easily edit, and hence change the primary functionality of the program that I wouldn’t wish to be editable.

Anyone ever ran into something like this, and if so, what was the setup that you used for your solution?

EDIT: Let me see if I can explain this better with an example. Say I have the following structure

category A
  -- action AB
      -- result 1
      -- result 2
      -- result 3
      -- result 4
      -- result 5
      -- result 6

where if I selected category A, and action AB, a one dice roll would select the result to be returned. The category, action, and result will never change both in name and in relationship (action AB will always be bound to category A, results within action AB will be bound to action AB, and the result contents will never change)

EDIT: No network usage would be expected for this application, as it was asked in one of the responses.

3

Create classes or interfaces for categories, actions, and results. Start with a list for categories. (You’ll need random access, so this should perhaps be a dictionary/map, though if you can ID them with integers an ArrayList might do.) Each Category will have a similar list of Action instances, and each Action will have a list of Result instances. (Actually, if these are interfaces rather than instances, each instance can have completely different code from every other, as best suits its purpose, and the lists can be different, or even nonexistent. You might choose results with an IF statement in one Action and an array in another.)

Now you create a new Result by creating a new instance of a subclass of the desired class, which implements the necessary interface. (For simple cases you can skip a step or two.) You create an Action similarly, then add Results to it. And a Category the same, and add Actions to it.

The key point here is the flexiblity. You can do just about anything and everything. Arrays in one place, switch statements in another, if-elses somewhere else. Also string-based dictionaries, etc., etc. While each Category looks and works, to outsiders, identical to every other, internally they can be completely different.

(Of course, for the simplest cases a simple nested if-else construct might do the whole job just as well.)

Even though the question is a little bit fuzzy, I can try to propose a solution.

As already mentioned by Neil, tree-like data structure can be useful here. I guess, if changing values is not needed (those are constants?), then it’s just a matter of not exposing them to the end user.

The lightweight solution could be binary serialization of hashes (objects, dictionaries, associative arrays – terminology depends on your language/framework/platform). If you need to keep them apart from the program, there are simple and efficient key-value storages (like Berkeley DB). It’s possible to use SQL-based approach even with sqlite – if I am not mistaken, even Firefox browser uses one under the hood: No database server needed. With sqlite, even full text search is possible. Sqlite works well even with in-memory backend, in case this is what is needed.

What is even better, user preferences can be also stored in the sqlite, in a different file.

Nowhere there is a mention that those constants need to be shared over the network, but even then serialization approach can be used.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật