View Single Post
  #3   Spotlight this post!  
Unread 31-10-2009, 00:20
Abrakadabra Abrakadabra is offline
Here We Go !!!
AKA: Scott Kukshtel, Mr. K
FRC #3467 (The Windham Windup!)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2002
Location: Windham, New Hampshire
Posts: 159
Abrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant futureAbrakadabra has a brilliant future
Re: Question regarding interfaces

As the Java Tutorials say:

Quote:
Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.
Basically, a Java Interface would be used by higher level code in place of a Class name when referring to an object that it is using. By "contract", any class object that implements that Interface will be required by the compiler to provide certain methods that take certain particular arguments and return certain particular values (i.e. the methods are all required and they all have well-defined "signatures"). This will allow the higher-level code to not worry about the internal implementation of a class, and instead can focus on just using that class via its "standard" methods.

If you later want to replace the lower-level class (or better yet, if it gets replaced for you down inside a library), your higher-level code doesn't care, because it just continues to use the same Interface.

This is just another expansion of the concept of "object abstraction" that got its more commonly known start with "function prototypes" in C++. Look them up for a possibly simpler explanation. Java Interfaces are essentially function prototypes applied to the entire class.

HTH.
Reply With Quote