I have never used generics yet but here is my understanding of them:

Say you had a class that operated on one type, for example a class that 
managed an internal array of integers. One of the operations might be to 
sort the array. Of course, there may be lots of additional operations 
included.

Once you created that class you decided that you also needed the same 
operations on arrays of strings. What choices do you have at that point?

Before generics you would have to re-implement the original class so 
that it operated on strings and include an internal array of strings 
instead of integers.

Or, you could try to expand the original class by overloading all the 
methods to handle strings. But here you would run into trouble because 
you would want either an internal array of integers or an array of 
strings but not both.

But using generics you could transform the original class into one which 
accepted the base type of the array as <T>, coding all the operations so 
that they worked with either integers or strings, and what you would 
have is one class to server both data types. The choice of data types 
would be deferred until you instantiated the class.

The instantiated class is NOT a derived class to which you would add 
additional features. Any features you would add that were specific to 
the type <T> might not be usable for other types so it would be better 
to add those features to the base class anyway.

Can you use the generic class as an ancestor and inherit from it? I 
don't know and I don't know how that would work.


_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to