Lookup Table Collection Design

Lookup Table Collection Design

Old forum URL: forums.lhotka.net/forums/t/1045.aspx


RealQuiet posted on Monday, August 28, 2006

I am working on an application with quite a few "lookup" tables.  I am building a LookupTableCollection class that holds LookupTable objects that are name value lists.  The LookupTableCollection class handles the caching and expiring for the members in the collection. 

The problem for me is that some of lookup table keys are integers and some are strings (not my database design).  I was going for something like:

class LookupTable<T> : NameValueListBase<T, string>

The problem with this is that I can't (or don't think I can) have a collection of LookupTable<T>.  I can have a collection of LookupTable<int> or LookupTable<string>, but the collection wouldn't be able to hold both.  As far as I can tell, I have two options (neither of which I like that much). 

I want to avoid creating a separate class for each lookup table.  The other option is to do this:

class LookupTable : NameValueListBase<object, string>

I don't really like this because I'm losing the advantage of the generics by having an object as the key to the name value list.

I would appreciate any guidance in the right direction on this.

Thanks!

figuerres replied on Monday, August 28, 2006

I don't have my Generics book handy -- it's at the office :-(

but I think if you do a bit of implimentation work you can have multiple generic's as parmaeters to form a complex type.

think "List of <T1,T2>"

where T1 is the Key Type and T2 is the Value Type

if you can't find the right example I'll look for the book at my office tomrow.

RealQuiet replied on Tuesday, August 29, 2006

I'm not sure that I am following you.  In my situation, I know that T2 will be a string, so I can specify that.  I think I may be trying to do something that I just can't do.  I would like to do something like this:

class LookupTable<T> : NameValueListBase<T, string>

class LookupTableList : NameValueListBase<string, LookupTable<string or int>>

But I think I have to specify string or int string or int and can't have both.  For now I have gone with:

class LookupTable : NameValueListBase<object, string>

class LookupTableList : NameValueListBase<string, LookupTable>

This is working, but I was hoping there was a better way to do this to take advantage of generics and not use object.

xal replied on Tuesday, August 29, 2006

You could make it:

class LookupTableList : NameValueListBase<string, IBindingList>

That will work, but you loose strong typing.
The other possibility is to have it like:

class LookupTableList <T> : NameValueListBase<string, LookupTable<T>>


But then you will need different lists for different types.

Lastly, you could just have a standard collection to hold your lists. Since they don't use generics, you can add whatever you want there...


Andrés

Copyright (c) Marimer LLC