<<< Week 11, Chapter 8, Interfaces and Abstract Classes     Index     Interface, Inheritance, and Composition >>>

2. Understanding contracts


  • Contract is an interface: what is to be done, not how.

  • Interface is like a class with a set of public operations but no attributes and no implementation.

  • A UML diagram of a Java interface:

     

      java interface

  • 
    public interface Nameable {
        String getName();
        void setName (String aName);
    }
    
    
  • Compare to:

    
    public abstract class Nameable
    {
        public abstract  String getName();
        public abstract void setName (String aName);
    
    }
    
    

<<< Week 11, Chapter 8, Interfaces and Abstract Classes     Index     Interface, Inheritance, and Composition >>>