![]() If all of the objects that you wish to use a specified interface on all descend from the same class that adds interface support, all is well. Unfortunately, this causes some problems as well. Likely it was done this way due to concerns of adding additional baggage to the entire object tree. There may be others as well, but these are the primary players. To use an object with interfaces, one must add special code for reference counting, or descend from (directly or indirectly) one of the specialized classes that already supports interfaces. In Delphi however, not all objects can be used with interfaces. Interfaces can also be useful in allowing limited exposure of private members. ![]() The goal of using an interface is to allow a common API among objects that otherwise do not share a common ancestor other than TObject. Interfaces allow much of what is often sought after with multiple inheritance, but without multiple inheritance's problems. However, there are valid cases for interfaces such as IEnumerable, data binding, IList, etc. I find that in many cases, they add complexity, rather than solve it. Unfortunately, there are some big limitations with Delphi interfaces, and in a critical area where interfaces are the most useful. Delphi's interfaces are rooted in COM interop, but in most cases are used for non COM purposes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |