Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

So not having much C++ background or practical experiance I know very little on generics, pretty much just what I read at MSDN today; I love the concept and performance gains and seems easy enough to use, but here's the question for you experianced folks.

 

I know it's a totally differant thing, but I use abstract factory pattern (I think is the correct pattern) to take a number of differant type of classes and expose a functionallity common to all of the through interfaces. Then I have a 'manager class' that will take any type of object that implements that interface and do work with it through the interface...(it took me a little while to figure out that interfaces are great for more than just gauranting a signature!) again I may have the wrong pattern listed, I'm just getting into design patterns (the correct naming of them) (btw, any good links on that would be cool). Anyway, I see a very strong resembelance to generics here, I don't have a feeling that this is the proper place for such a thing, and it seems generics should be used on more of a consumed object type than a object type that does management or manipulation, if you follow the differance I mean by that... I think there are some things about generics that haven't quite clicked yet and I'm looking for some good advice on the use and concepts of them.

 

Thanks!

Posted
A quick explanation of Generics is that they are collections, equivalent to ArrayList, HashTable, SortedList, etc. that can be strongly typed simply by you designating what type they accept at design time. That way, instead of a Collections.ArrayList being able to contain an Integer, a String and any other Object you care to Add to it, a Generics.List that you declare as being Of Integer will throw an exception if you try to Add anything but an integer to it. In the case of a SortedList or HashTable, the Generics version requires you to declare the type of both the keys and the values. You can declare either as being Of Object if you only want one to be strongly typed.
  • Administrators
Posted

Collections are one of the more common uses of generics - how ever they can be used for any generic ;) code.

Also generics are a compile time thing - the compiler itself will prevent you using incorrect data types, the errors will be caught at compile time rather than run-time.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...