June 7, 2002 - The Interface's Advantages | WebReference

June 7, 2002 - The Interface's Advantages

Yehuda Shiran June 7, 2002
The Interface's Advantages
Tips: June 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

The Interface concept is one of the cornerstones of object oriented programming languages. Interfaces are very similar to classes. They are also defined by the exact same syntax. Interfaces differ from classes in that they don't include any member implementation. An interface can have properties and method interfaces only. An interface does not have any method implementation. It can include a method declaration but no function body.

By itself, interfaces are not very useful. You cannot create instances of interfaces. You can implement interfaces by useful classes from which you can create instances. Interfaces are instrumental in enforcing object oriented design methodologies. One group may specify the interface for other groups to follow. Each group may implement its own function bodies, but all groups will adhere to the same interface, defined a priori. It comes back to the first and foremost incentive for object oriented programming: encapsulation. You don't care how a capability is implemented. You, as a programmer, are exposed only to the interface. This is also a good way to watch after the system architecture. You don't let everyone on the team define his or her own interfaces. One central group will usually define them for the rest. Interfaces are a good way to define methods for the whole project.

To learn more about JScript .NET, go to Column 110, JScript .NET, Part IV: Inheritance.