8.12

4.2 Interfaces🔗ℹ

The interface definition form for an interface is similar to class, but without fields. A class form can declare that the class implements an interface through an implements clause. When a class implements an interface, then instances of the class satify the interface annotation, similar to the way that a subclass instances satifies the superclass annotation. A class can have at most one superclass. but it can implement any number of interfaces. An interface is never final, so nonfinal is not needed in an interface.

interface Shape

interface Dance

class Square(side):

  implements:

    Shape

    Dance

> def s = Square(10)

> s is_a Shape

#true

> s is_a Dance

#true

Interfaces can extend other interfaces. Unlike classes extending at one most superclass, interfaces can extend any number of superinterfaces.

interface MailingAddress

interface Residence

interface HomeAddress:

  extends:

    MailingAddress

    Residence

interface LawncareClient

class SingleFamilyHome(street, city, state, zip):

  implements:

    HomeAddress

    LawncareClient