Neha Garg wrote: > have a doubt regarding which implementation is best, inheriting > TCollection, TObjectList or inheriting from TObject and using a property of > TList and expose functionality related to Add, Get etc. > With TCollection, the problem is that one has to write a TCollectionItem and > then the collection is bound with that Item only, you cannot have different > type of collections for different items.
TCollection is only good if you need to expose the property at design time in the Object Inspector. Otherwise, you can always build a better collection class that does what you need without imposing the design restrictions that come with TCollection. The items in a TCollection cannot exist outside a TCollection. You cannot create a TCollectionItem without telling it which collection owns it. (You can move an item from one collection to another afterward.) When you descend from TList, remember that your class inherits *everything* about a TList, even the parts you might not want. You cannot hide a method, no matter how hard you try. TList is not a suitable base class if you intend to write a type-safe list. If I have a reference to your TList descendant, I can assign it to a variable of type TList and then add anything I want to it. If you want a type-safe list, then it should descend from a class that doesn't already provide list-like methods of its own. TObject is a good choice. Use a TList to help implement your custom list class, if you want. Consider how Contnrs.TOrderedList does not descend from TList. If it did, then it would have inherited TList's Insert method and Items property, which go against the idea of having a limited-access list. Only write a descendant class when you need to take advantage of the "is a" relationship between classes. -- Rob _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

