[fpc-pascal]TCollection question

Matt Emson memsom at interalpha.co.uk
Mon Jul 7 12:08:15 CEST 2003


Think of my  code as a design pattern for a list, or possibly a template.
You could replace the class name you are storing everywhere in the code and
would then have a completely different List class. A bit like a C++
template, except you have to define all the code each time.

> A question about your basic-design and using TList (and descandents in
> general)...
> Could I not do this:
> TMyList = class(TList);

Yes, but a wrapper gives more flexibility. You can give the class user the
exact interface you had in mind, rather than forcing the whole of the TList
legacy onto them. The OO term of the month is Aggregation here.

> And thereby extend the basic TList class into a custom List ?
> The way you use TList is as a private variable in a generic class.

Sure you could, but using a wrapper allows you to take more control.

To be honest, you should use a TObjectList anyway. The TObjectList already
does almost everything you desire except the specific named class
Add/Insert/Items functionality.


More information about the fpc-pascal mailing list