Embarcadero DelphiInterfaces


Remarks

Interfaces are used to describe the needed information and the expected output of methods and classes, without providing information of the explicit implementation.

Classes can implement interfaces, and interfaces can inherit from each other. If a class is implementing an interface, this means all functions and procedures exposed by the interface exist in the class.

A special aspect of interfaces in delphi is that instances of interfaces have a lifetime management based on reference counting. The lifetime of class instances has to be managed manually.

Considering all these aspects, interfaces can be used to achieve different goals:

  • Provide multiple different implementations for operations (e.g. saving in a file, database or sending as E-Mail, all as Interface "SaveData")
  • Reduce dependencies, improving the decoupling and thus making the code better maintainable and testable
  • Work with instances in multiple units without getting troubled by lifetime management (though even here pitfalls exist, beware!)