from  Joseph Bergin   Nov 25 (2 days ago)
 reply-to  AP Computer Science 
 to  AP Computer Science 
 date  Nov 25, 2006 11:47 AM
 subject  Re: [ap-compsci] Interfaces

My explanation is that an interface is like the owner's manual for (a car, a bike, an ipod, ... whatever). A Class is like a set of engineering drawings for the same thing. An interface tells you how you can use a thing. A class tells you how you can build a thing.

I sometimes also describe a class as a production line that makes the thing (rather than just the drawings. ) With this idea, an abstract class is like a line that partially builds a thing that is never sold "as is" but is always completed by another line (the class).

Note that interfaces are VERY important in Java. If all of your method parameters have interface type, then your program will be better (and more useful) than if they have class type). Interface typing is much more important than subclass typing. In fact, it is much closer to our usual metaphor to explain it. Note that animal, mammal, etc are never concrete types. There are NO animals that are not tigers or field mice, or whatever. Only the leaves of the

animal/vegetable/mineral classification tree are concrete types (classes). There is good advice that you should build this way also. Perhaps this sounds extreme to you, but it is good advice from experts. All classes final, all inheritance from interfaces.

No, I don't go to that extreme in my own practice, but recognize that most of my programs would be better and most of my errors of design would disappear if I did.

Joseph Bergin, Professor
Pace University, Computer Science, One Pace Plaza, NY NY 10038
EMAIL jbergin@pace.edu
HOMEPAGE http://csis.pace.edu/~bergin/
---
"In theory, theory is the same as practice, but not in practice ."
- Fnord Bjørnberger

On the Internet Since March 9, 1996    URL:   http://www.comscigate.com    Last Revised:   November 27, 2006.