Prev | Current Page 219 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"

For our purposes of ordering Automobiles, we thought that the
84 PROGRAMMING IN JAVA [CHAP. 5
toString() representation of Automobiles sorted in ASCIIbetical order would be fine. Older
cars will be ordered first, and among cars of the same year, cars will be sorted ASCIIbetically by make and
model.
The interface idea is similar to the idea of a class, in that an interface creates a new data type. When
the class Automobile implements the interface Comparable, instances of Automobile can also be
treated as instances of Comparable. Just as good design of a class hierarchy can reduce programming and
improve reliability, good interface design can also.
For instance, the sort() method of the Java Collections class will sort lists of Comparable
objects. Our Automobile class implements Comparable, Java??™s String class implements Comparable,
Java??™s Date class implements Comparable, etc. One sort() method will work for any group of objects
whose class implements Comparable. That alone is a great example of code reuse.
It??™s easy to design and use your own interfaces, too. However, in this brief chapter we will not be discussing
that topic.
ERROR HANDLING
Java uses Exceptions to represent error conditions.


Pages:
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
pompy ciepła pustaki szklane profesjonalne wizualizacje 3d Battlefield 3 wygraj peb ziemme.bizor.pl