Delphi – Why should I use Tcollections.createlist instead of tList.create?

I added map(), reduce() and where(qlint: string) to my Spring4D branch.
When I wrote these functions, I found the behavior of the list There are differences when they are created in different ways.

If I use TList to create them. Create enumerable objects are of type TSomeClass.

If I use TCollections .CreateList creates them. The objects in the enumeration are of type TObject.

So the question is:

Is there any shortcomings in using TList< TSomeClass> .create?
In other words: Why should I use TCollections.CreateList?

By the way: using TCollections.CreateList I have a TObjectList instead of a TList. So it should be called TCollections.CreateObjectList… but that is another story.

According to the compiler version, many Spring.Collections.TCollections.Create methods are applying what the compiler can’t achieve: folding the implementation into a very simple In the generic class. Some methods are made from XE, and some are just because of XE7 (GetTypeKind internal function enables type resolution at compile time-see for example no parameter TCollections.CreateList).

If you want to create many different types of IList, this will greatly reduce the binary size. (where T is a class or interface) because it folds them into a TFolded (object|interface) list. However, through the interface, you can access the item in the specified way, and the ElementType property also returns the correct type, not just TObject or IInterface. In Berlin, it adds less than 1K for each different object list, and if due to Involving all the internal classes involved in different operations that can be called on IList without applying folding, it will increase by about 80K.

As for TCollections.CreateList returns IList by TFoldedObjectList Supported when T is a fully designed class. Since OwnsObject is passed as False, it has exactly the same behavior as TList.

The Spring4D collection is based on interfaces, so As long as its behavior corresponds to the contract of the interface, the classes behind the interface are irrelevant.

Make sure you only carry lists as IList instead of TList-you can create them in both directions (using The TCollections method is the benefit I mentioned before). In our own application, some places are still using the constructor of the class, and many other places are using the static methods in Spring.Collections.TCollections.

< p>BTW:

I have seen activities in your fork and imo, there is no need to implement Map/Reduce, because it has Exist. Since Spring4D collections are modeled after .NET, they are called Select and Aggregate (see Spring.Collections.TEnumerable). They are not available on IEnumerable. Directly but because the interface must not be universal Parameterized methods.

I added map(), reduce() and where(qlint: string) to my Spring4D branch.
When I write these When functioning, I found that the behavior of lists is different when they are created in different ways.

If I use TList to create them. Creating enumerable objects is of type TSomeClass.

If I use TCollections.CreateList to create them. The objects in the enumeration are of type TObject.

So the problem is:

Use TList< TSomeClass> .create Are there any shortcomings?
In other words: Why should I use TCollections.CreateList?

By the way: using TCollections.CreateList I have a TObjectList instead of a TList. So it should be called TCollections.CreateObjectList… but that is another story.

According to the compiler version, many Spring.Collections.TCollections.Create methods are applying what the compiler cannot achieve: folding the implementation into a very simple generic class. Some methods start with XE Some of it is just because of XE7 (GetTypeKind internal function enables type resolution at compile time-see for example no parameter TCollections.CreateList).

If you want to create many different types of IList , which will greatly reduce the binary size. (where T is a class or interface) because it folds them into a TFolded (object|interface) list. However, through the interface, you can access in the specified way Item, and the ElementType property also returns the correct type, not just TObject or IInterface. In Berlin, it adds less than 1K for each different object list, and if it involves different operations that can be called on IList Involving all internal classes without applying folding, it will increase by about 80K.

As for TCollections.CreateListreturns IListsupported by TFoldedObjectListWhen T is a completely according to the design Since OwnsObject is passed as False, it has exactly the same behavior as TList.

The Spring4D collection is interface-based, so as long as its behavior corresponds to the contract of the interface, the interface The latter classes are irrelevant.

Make sure you only carry lists as IList instead of TList-you can create them in both directions (the benefits I mentioned before when using the TCollections method). In our own application, some places are still using class constructors, while many other places are using static methods in Spring.Collections.TCollections.

BTW:

I Seeing the activity in your fork and imo, there is no need to implement Map/Reduce because it already exists. Since Spring4D collections are modeled after .NET, they are called Select and Aggregate (see Spri ng.Collections.TEnumerable). They are not available on IEnumerable. Directly but because the interface must have no general parameterization method.

Leave a Comment

Your email address will not be published.