473,379 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

A dynamic set of "constants"?

JD
In C#, I'm wondering what the best way is to have the equivalent of a sort
of "dynamic" enumeration... here's the deal --

Assume there's a data table of Widgets where each widget has an ID, a name,
and a type. The table will contain a few widgets initially, but could grow
to 20-30 or so. Each widget is of a certain WidgetType as well. For now,
suppose it looks like this:

ID Name Type
1 Foo 1
2 Bar 2
3 Rat 1
4 Fink 3

The WidgetType table might look like this:

ID Name
1 Square
2 Circle
3 Triangle

Throughout the application, these widgets and widget types will be referred
to using the ID value. While it should be rare, it's not unreasonable to
think that those ID values and/or names could change. Similarly, the
introduction of new widgets will be rare and will nearly always be
accompanied by an updated build. Assume that there will also be a "widget
manager" that governs the set of widgets and provides widget-related
services.

The ideal approach from a development perspective would be an enum so that
the developer could simply type "Widgets." and get the intellisense list of
available widgets. Similarly, they type "WidgetTypes." and get the set of
available types. Because the values and/or set of widgets could change, that
would seem to be out.

I could create a public hashtable member on the widget manager, and then
populate it at runtime, so that the developer now uses something like:

WidgetMgr.Widgets["Foo"]
WidgetMgr.WidgetTypes["Square"]

.... but that means they have to know the corresponding Name values to get at
the ID.

While I can think of a few "workable" methods, what's a "best practice" way
to manage this collection of widgets, and provide users of the class library
with a relatively easy way to get at individual widgets in the set? Are
indexers a possible solution to this?

Thanks,

J
Nov 15 '05 #1
0 939

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
7
by: Steve Jorgensen | last post by:
Here is some code to generate code for raising and getting information about custom errors in an application. Executing the GenerateXyzErrDefs procedure generates the code. <tblXyzError>...
35
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And...
6
by: kobu.selva | last post by:
I was recently part of a little debate on the issue of whether constants and string literals are considered "data objects" in C. I'm more confused now than before. I was always under the...
46
by: TTroy | last post by:
Hi, I'm just wondering why people/books/experts say "the function returns a pointer to.." or "we have to send scanf a pointer to.." instead of "the function returns the address of.." or "we have...
48
by: mahurshi | last post by:
I am new to c++ classes. I defined this "cDie" class that would return a value between 1 and 6 (inclusive) It runs fine and gives no warnings during compilation. I was wondering if you guys...
25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.