Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Software Development 1Slide 1 Interfaces Outline:Outline: –Generic interface versus Java interface –What a (Java) interface is: Its syntaxIts.

Similar presentations


Presentation on theme: "Fundamentals of Software Development 1Slide 1 Interfaces Outline:Outline: –Generic interface versus Java interface –What a (Java) interface is: Its syntaxIts."— Presentation transcript:

1 Fundamentals of Software Development 1Slide 1 Interfaces Outline:Outline: –Generic interface versus Java interface –What a (Java) interface is: Its syntaxIts syntax What it saysWhat it says What it does NOT sayWhat it does NOT say How it is used, why it is usefulHow it is used, why it is useful –How interfaces are used in WordGames UML class diagram for WordGamesUML class diagram for WordGames –WordGames An application of interfacesAn application of interfaces

2 Fundamentals of Software Development 1Slide 2 Generic interfaces Generic computer-science interfaceGeneric computer-science interface –The “face” that one entity shows others: What services it providesWhat services it provides What information it expectsWhat information it expects –Physical examples: Computer InterfacesComputer Interfaces StethoscopeStethoscope TelephoneTelephone CameraCamera ToasterToaster

3 Fundamentals of Software Development 1Slide 3 Why have interfaces? A Java interface is the “face” that one class shows othersA 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 contractSo an interface specifies a contract public interface ClockRadio { public Time getTime(); public Time getTime(); public void setTime(Time x); public void setTime(Time x); public void setTime(Time x, Station s); public void setTime(Time x, Station s);} Example of a Java interface

4 Fundamentals of Software Development 1Slide 4 Why have interfaces? Java interfaces are important because:Java interfaces are important because: –They provide for software reuse. For example: I provide a StringTransformable interfaceI provide a StringTransformable interface You provide classes that implement StringTransformableYou provide classes that implement StringTransformable Our separately-written code works together seamlessly!Our separately-written code works together seamlessly! –They provide genericity. For example: My code declares each of your things as a StringTransformable thingMy code declares each of your things as a StringTransformable thing You provide various implementations of StringTransformableYou provide various implementations of StringTransformable –e.g. Capitalizer, NameDropper, UbbyDubber, … My code is generic – it doesn’t care what implementation of StringTransformable you supply!My code is generic – it doesn’t care what implementation of StringTransformable you supply! Interfaces can (and should) be used as types public interface ClockRadio { public Time getTime(); public Time getTime(); public void setTime(Time x); public void setTime(Time x); public void setTime(Time x, Station s); public void setTime(Time x, Station s);}

5 Fundamentals of Software Development 1Slide 5 UML class diagram for WordGames CapitalizerNameDropperxxx … StringTransformable --------------------------- transform(String) : String All our stuff The StringTransformable interface is how our code knows how to “connect” to your code Questions on this important idea?

6 Fundamentals of Software Development 1Slide 6 Java Interfaces: Summary A Java interface is the “face” that one class shows othersA 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 contractSo an interface provides a contract Java interfaces are important because they provide for:Java interfaces are important because they provide for: –Software reuse –Genericity From now on, “interface” means “Java interface” to us public interface ClockRadio { public Time getTime(); public Time getTime(); public void setTime(Time x); public void setTime(Time x); public void setTime(Time x, Station s); public void setTime(Time x, Station s);}


Download ppt "Fundamentals of Software Development 1Slide 1 Interfaces Outline:Outline: –Generic interface versus Java interface –What a (Java) interface is: Its syntaxIts."

Similar presentations


Ads by Google