name: inverse layout: true class: taylor msoe --- class: center, middle .title[ # Interfaces Introduction ] ??? Toggle speaker view by pressing P Pressing C clones the slideshow view, which is the view to put on the projector if you're using speaker view. Press ? to toggle keyboard commands help. --- # Interfaces * An interface advertises functionality but doesn't provide an implementation -- * Cannot create objects from an interface -- * An interface reference can point to any object from a class that implements the interface -- * The reference determines what methods can be called -- * The implementing class **can-do** what the interface claims for functionality --- # Inteface Example * [`CharSequence`](https://javadoc.taylorial.com/java.base/lang/CharSequence.html) - a readable sequence of `char` values -- ``` public interface CharSequence { char charAt(int index); int length(); CharSequence subSequence(int start, int end); String toString(); } ``` -- * Methods are `public` by default -- * The `String` class implements the `CharSequence` interface ``` public class String implements CharSequence { ``` -- + This is a simplified declaration of the `String` class --- # Intefaces Continued... * Other classes also implement the `CharSequence` interface: `StringBuffer`, `StringBuilder`, `CharBuffer`, `Segment` -- * Whenever a `CharSequence` is needed, an object from any of the implementing classes will work -- * Summary: + A class that implements an interface has a **can-do** relationship