Now that we have explored how to define generic interfaces and combine them with the use of generic and specific classes, we can get back to having a second look to the Generics.Default unit. This unit defines two generic comparison interfaces:
These classes are implemented by some generic and specific classes, listed below (with no implementation details): type
TComparer<T> = class(TInterfacedObject, IComparer<T>) TEqualityComparer<T> = class(
TInterfacedObject, IEqualityComparer<T>) TCustomComparer<T> = class(TSingletonImplementation,
IComparer<T>, IEqualityComparer<T>) TStringComparer = class(TCustomComparer<string>)
In the listing above you can see that the base class used by the generic implementations of the interfaces is either the classic reference-counted TInterfacedObject class or the new TSingletonImplementation class. This is an oddly named87 class that provides a basic implementation of IInterface with no reference counting.
As we have already seen in the "Sorting a TList<T>" section earlier in this chapter, these comparison classes are used by the generic containers. To
87 The term singleton is generally used to define a class of which you can create only one instance, and not one with no reference counting. I consider this quite a misnomer.
make things more complicated, though, the Generics.Default unit relies quite heavily on anonymous methods, so you should probably look at it only after reading the next chapter.
Was this article helpful?
What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.