Skip to content

Interface

Sharina Stubbs edited this page Mar 4, 2020 · 5 revisions

Terminology:

implements interface

vs

extends class

Implementing an interface means you have to implement methods in that interface.

About:

Interfaces define methods that exist, but they don't actually implement those methods. They specify behaviors.

How we implement an interface

We have to define the methods that it specifies.

See code demo: https://github.com/codefellows/seattle-java-401d6/tree/master/class-07

See FrontRow for 9/24/19 at 3:45pm for code demo on making Interface

Examples

  • User Details in Spring apps (Security)
  • View Adapter in Android (Recycler Views)

In both of these case, the code was written to interact with another framework that you didn't have to write.

  • Recycler View
    • Code written by Android team - when the user scrolls, take the rows from the top, move them to the bottom, etc.
    • What data goes into a row is info that is needed by the Recycler View.
  • Spring Security
    • Code written for us - when user tries to log in, check their password and save user as the principal. We never had to set up what the principal meant.
    • We had to write: for a given user, what is their username and password. We had to implement the getusername and getpassword methods.

We specify the parts that make the code unique, but we are working within a giant overlying architecture that we want to be part of, when working with interfaces.

Clone this wiki locally