02 Prepare : Reading
Java Interfaces
Objectives
Understand the design principle "Program to an interface, not an implementation".
Learn when it is appropriate to use an interface.
Learn how to implement an interface in Java.
Software Design Principle
Program to an interface, not an implementation.
Using interfaces makes our code more flexible. To understand why this is:
First, read this official description of interfaces from Oracle's Java Documentation in order to get a basic idea of what an interface is.
Next, watch this video, which shows how interfaces can help us avoid a particular design issue:
Then, read the first answer to this Stack Overflow question to understand the main advantage of interfaces.
Finally, read the top four answers to this Stack Overflow post to see other advantages and thoughts about interfaces.
After reading that material, you should understand the advantages provided by programming to an interface rather than an implementation.
Namely, it allows our code to move away from this design: "I need this specific class in order to do this work." and instead use this more flexible idea: "I can use any class that can do this kind of thing in order to do this work."
Java Coding
Now that you know what interfaces are and why they are useful, read through this tutorial for more details on how to use interfaces in Java.
Reading Quiz
Don't forget to take the Reading Quiz in I-Learn. This quiz can be taken as many times as you like, but you must score at least 90% to pass. If you fail the quiz, review the relevant parts of the reading and try again.
As before, one of the quiz questions is a "deep thought" question whose answer won't come directly from the reading.