Interfaces Presented By Parag Shah http://www.adaptivelearningonline.net
Agenda Java and multiple inheritance Declaring interfaces Using interfaces
Java And Multiple Inheritance - 1 Java does not have multiple inheritance Inheritance gives us two things Code reuse Ability to represent the object polymorphically as the super type
Java And Multiple Inheritance - 2 Code reuse in multiple inheritance is risky The ability to represent a class polymorphically as a type other than the superclass may be useful Interfaces allow the latter but not the former
Interfaces Interfaces are defined with the interface keyword Interfaces do not have any code All attributes are public static final public interface Ignorable { public boolean isValid(); }
Implementing An Interface Any class can implement an interface Use the implements keyword A class can implement multiple interfaces The class must implement all the methods declared in the interface See [biz.adaptivesoftware.examples.interfaces]
Marker Interfaces Some interfaces are used as flags for the JVM Cloneable Serializable SingleThreadModel
Summary Interfaces allow us to polymorphically represent a class as types across inheritance trees Interfaces are implemented with the implements keyword Do not CREATE interfaces for non standard use such as marker interfaces

Interfaces In Java

  • 1.
    Interfaces Presented ByParag Shah http://www.adaptivelearningonline.net
  • 2.
    Agenda Java andmultiple inheritance Declaring interfaces Using interfaces
  • 3.
    Java And MultipleInheritance - 1 Java does not have multiple inheritance Inheritance gives us two things Code reuse Ability to represent the object polymorphically as the super type
  • 4.
    Java And MultipleInheritance - 2 Code reuse in multiple inheritance is risky The ability to represent a class polymorphically as a type other than the superclass may be useful Interfaces allow the latter but not the former
  • 5.
    Interfaces Interfaces aredefined with the interface keyword Interfaces do not have any code All attributes are public static final public interface Ignorable { public boolean isValid(); }
  • 6.
    Implementing An InterfaceAny class can implement an interface Use the implements keyword A class can implement multiple interfaces The class must implement all the methods declared in the interface See [biz.adaptivesoftware.examples.interfaces]
  • 7.
    Marker Interfaces Some interfaces are used as flags for the JVM Cloneable Serializable SingleThreadModel
  • 8.
    Summary Interfaces allowus to polymorphically represent a class as types across inheritance trees Interfaces are implemented with the implements keyword Do not CREATE interfaces for non standard use such as marker interfaces