2008-04-25

Delphi Basics: Interface command

The Interface keyword is used in two different ways.

Version 1

It starts the definition of external interface of a Unit. Declarations here are externally visible by other units. All of these declarations must be implemented in the Implementation section.

The Uses statement, if present, must be at the start.

Version 2

In Object Oriented programming, we often use Abstract class methods in a base class as a placeholder. All derived classes must implement these methods.

Taking this one step further, an Interface defines a grouping of just abstract properties and methods. It provides a template for a class to use to ensure consistency. It is like a class with only abstract methods. It has the benefits that classes can be based on one parent class, and implement one or more interfaces. It adds a predictable flavour of operation to each class that implements the interface.

Take a look at the Delphi tutorial for more on this complex subject.

0 comments: