Interfaces - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Interfaces

Description:

Toaster. Fundamentals of Software Development 1. Slide 3. Why have interfaces? A Java interface is the 'face' that one class shows others ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 7
Provided by: davidmutch
Category:

less

Transcript and Presenter's Notes

Title: Interfaces


1
Interfaces
  • Outline
  • Generic interface versus Java interface
  • What a (Java) interface is
  • Its syntax
  • What it says
  • What it does NOT say
  • How it is used, why it is useful
  • How interfaces are used in WordGames
  • UML class diagram for WordGames
  • WordGames
  • An application of interfaces

2
Generic interfaces
  • Generic computer-science interface
  • The face that one entity shows others
  • What services it provides
  • What information it expects
  • Physical examples
  • Computer Interfaces
  • Stethoscope
  • Telephone
  • Camera
  • Toaster

3
Why have interfaces?
  • A Java interface is the face that one class
    shows others
  • An interface contains the signature but not body
    for each method
  • Any class that implements an interface must
    provide the methods listed in the interface
  • So an interface specifies a contract

public interface ClockRadio public Time
getTime() public void setTime(Time x)
public void setTime(Time x, Station s)
Example of a Java interface
4
Why have interfaces?
public interface ClockRadio public Time
getTime() public void setTime(Time x)
public void setTime(Time x, Station s)
  • Java interfaces are important because
  • They provide for software reuse. For example
  • I provide a StringTransformable interface
  • You provide classes that implement
    StringTransformable
  • Our separately-written code works together
    seamlessly!
  • They provide genericity. For example
  • My code declares each of your things as a
    StringTransformable thing
  • You provide various implementations of
    StringTransformable
  • e.g. Capitalizer, NameDropper, UbbyDubber,
  • My code is generic it doesnt care what
    implementation of StringTransformable you supply!

Interfaces can (and should) be used as types
5
UML class diagram for WordGames
All our stuff
The StringTransformable interface is how our code
knows how to connect to your code
ltltinterfacegtStringTransformable -----------------
---------- transform(String) String
Capitalizer
NameDropper
xxx
xxx

Questions on this important idea?
6
Java InterfacesSummary
public interface ClockRadio public Time
getTime() public void setTime(Time x)
public void setTime(Time x, Station s)
  • A Java interface is the face that one class
    shows others
  • An interface contains the signature but not body
    for each method
  • Any class that implements an interface must
    provide the methods listed in the interface
  • So an interface provides a contract
  • Java interfaces are important because they
    provide for
  • Software reuse
  • Genericity

From now on, interface means Java interface
to us
Write a Comment
User Comments (0)
About PowerShow.com