Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
By incorporating interfaces into your next project, you will noticebenefits throughout the lifecycle of your development effort. The technique of coding to interfaces rather than objects will improve the efficiency of the development team by:
Because object-oriented development efforts involve the interactions of objects, it is essential to develop and enforce strong contracts between those objects. The technique of coding to interfaces involves using interfaces, rather than objects, as the primary method of communication.
This article will introduce the user to the concept of coding to interfaces through a simple example. A detailed example will follow, helping demonstrate the value of this scheme in a larger system requiring multiple developers. Before we get to the sample code, however, let's look at the benefits of coding to interfaces.
The Java interface is a development contract. It ensures that a particular object satisfies a given set of methods. Interfaces
are used throughout the Java API to specify the necessary functionality for object interaction. Examples of interface use
are callback mechanisms (Event Listeners), patterns (Observer), and specifications (Runnable, Serializable).
Coding to interfaces is a technique by which developers can expose certain methods of an object to other objects in the system. The developers who receive implementations of these interfaces have the ability to code to the interface in place of coding to the object itself. In other words, the developers would write code that did not interact directly with an object as such, but rather with the implementation of that object's interface.
Another reason to code to interfaces rather than to objects is that it provides higher efficiency in the various phases of a system's lifecycle:
There is some overhead associated with this development technique, due to the required code infrastructure. This infrastructure includes both interfaces for the interactions between objects and invocation code to create implementations of interfaces. This overhead is insignificant when compared to the ease and benefit of using interfaces as described.