[Mono-list] How do I reference generic classes in C#???
jbcooley at tuxinthebox.net
Tue Jan 13 17:11:32 EST 2009
On Tue, Jan 13, 2009 at 3:58 PM, Luke B <muchomuse at gmail.com> wrote:
> there are a million ways to make it work. Its about what's intuitive, what
> sits easy in the mind. And what sits easy in my mind is that, a List is a
> List whether its of groceries or things to do, and a Mug is a Mug whether it
> has Cocoa in it or Coffee. And I should be able to refer to a List or Mug as
> an entity regardless of what they contain.
> But whatever, this is just my observation. And I'm pretty new to DotNet, I
> may yet "see the light". Give me 6 months of getting used to DotNet and if I
> still see things the same way, I'll come back and we'll have a real debate
> on it. :)
There are a million ways to make it work, but a common pattern used in
.NET is to have a non-generic base class/interface. List<T> also
implements IList. You could have your Mug<T> class derive from a Mug
class. This means that a coffee mug and a cocoa mug are now both
mugs. I like it this way, but it is an issue I often encounter when
writing my own generic classes.
More information about the Mono-list