Overview of Interfaces


Interfaces and abstract classes achieve two things. First, they establish the definition of a class and provide the list of method signatures that subclasses will use. This list becomes a binding agreement between the superclass and its subclasses. Second, they enable programmers to subdivide their workload and distribute it among different people or groups to increase productivity. For example, suppose you have two teams of developers. One team specializes on the presentation layer, and the other focuses on the database. If the two groups do not know what each other is doing, chaos will ensue. The presentation team needs to know what data the database team will hand them for presentation. Conversely, the database team needs to know what the presentation team wants to be displayed.

On a technical level, each team needs to know some amount of detail about the other's code to test and integrate their code into the whole. Furthermore, the testing team wants to start preparing scenarios to test the work of both teams. The documentation team wants to start writing manuals. The deployment team wants to start writing installation scripts. Beyond the original two development teams, other people rely on the code's structure to do their jobs.

It helps if everyone knows the list of method signatures, often referred to as the application programming interface (API). If an interface is defined, both the presentation and database teams can start coding simultaneously . The testing, documentation, and deployment teams can also start, if not complete, contributing to the overall project.

The analogy of building a house applies here. After the architectural drawings are completed, the tasks of plumbing, wiring, roofing, landscaping, foundation work, and so forth can begin. Everyone can start the actual work or at least plan and set up his or her tasks . The key to having many people work on the same objective is to have a common definition of the house details that all teams share. When work overlaps boundaries, you need a common definition so that each team knows how the other teams' work affects its own work. Interfaces and abstract classes function like software architectural drawings, containing the agreed-on definitions of methods and variables that overlap boundaries.

If the entity schema for a person is defined early, the database and presentation people can both code to this schema. For example, if a person is defined as having a first and last name , an address, and a phone, the HTML page can be written to display these customer attributes. At the same time, the database programmer can create a table with that schema and write a class that encapsulates a person's definition. The presentation and database programmers can work simultaneously. Although this aspect of simultaneous programming is not often considered , interfaces and abstract classes add efficiency and a way to manage software projects.

Understanding the difference between abstract classes and interfaces is important. The following sections delve into details on abstract classes and then interfaces, and finally, the two are compared. If you want to see the comparison first, jump to the section "Interfaces Versus Abstract Classes."



JavaT 2 Developer Exam CramT 2 (Exam CX-310-252A and CX-310-027)
JavaT 2 Developer Exam CramT 2 (Exam CX-310-252A and CX-310-027)
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 187

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net