1. Home
  2. Computing & Technology
  3. Delphi Programming

Readers Respond: Have you implemented any Interfaces lately? Why, what for?
Responses: 3

By , About.com Guide

Most Delphi developers when they think of interfaces they think of COM programming. However, interfaces are just an OOP feature of the language - they are not tied to COM specifically. Interfaces can be defined and implemented in a Delphi application without touching COM at all.

Have you ever created (and implemented) your own interface? Why?

Share with us some real-world examples in using interfaces in Delphi applications... Why do you do Interfaces?

Adding functionality to existing classes

Interfaces are a nice way of asking if an object "supports some functionality". We could do this by using "is" (eg: "if obj is TWinControl") but this requires objects to fall within a certain class hierarchy implementing the required functionality. I use interfaces for a design application where objects need functionality like printing. If I rely on class hierarchy to determine if objects support common functionality then I have to either a) re-create an entire control class hierarchy (buttons, edits, labels, memos etc) that include a base class with the common functionality or b) implement the common functionality in a non-OOP if-then-else construct. With interfaces, I can derive new classes directly from existing classes (I don't have to re-write my own versions of TLabel, TEdit, TMemo etc) and simply implement the new interfaces. To see if a control has the functionality we simply ask if the object "supports" the interface.
—Guest Etherman

Why do I use interfaces

I use interfaces to share methods and properties in classes that do not inherit from the same parents. For instance to create a set of data-aware controls having common methods like Load, Save, AsText, ...
—Guest Pascal Piret

Interfaces sounded too complex for me...

But after reading this article ... I see dozens of places in my applications where interfaces will come handy. Thanks!
—rascal1936

Why do you do Interfaces?

Have you implemented any Interfaces lately? Why, what for?

Receive a one-time notification when your response is published.

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. OOP in Delphi
  6. Using Interfaces in Delphi programming?>

©2009 About.com, a part of The New York Times Company.

All rights reserved.