bri189a Posted June 18, 2005 Posted June 18, 2005 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! Quote
Moderators Robby Posted June 18, 2005 Moderators Posted June 18, 2005 Here's very simple explanation of generics... http://dotnet.org.za/eduard/archive/2004/08/19/3441.aspx Quote Visit...Bassic Software
jmcilhinney Posted June 19, 2005 Posted June 19, 2005 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. Quote
IngisKahn Posted June 19, 2005 Posted June 19, 2005 Generics have many many uses beyond collections. Quote "Who is John Galt?"
jmcilhinney Posted June 20, 2005 Posted June 20, 2005 My apologies. Every reference I have previously read has been related to collections. I guess I should do some reading myself before posting "definitive" definitions :o Quote
Administrators PlausiblyDamp Posted June 20, 2005 Administrators Posted June 20, 2005 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.