SlideShare a Scribd company logo
Interfaces
Chapter 9
9
Creating Interfaces
An interface is a contract.
Every class that implements the interface
must provide the interface’s defined
methods.
Each class implements the methods
however it sees fit.
A class can implement multiple
interfaces.
9
Declaring the Interface
Similar to a class declaration but uses the
interface keyword
The extends keyword can be used to
extend interfaces.
9
Interface Restrictions
Interfaces:
Cannot have member fields
Can define constants
Cannot have methods with
implementation; all methods in an
interface are implicitly abstract
Cannot be instantiated
Cannot define constructors
9
Implementing Multiple Interfaces:
The Debuggable Interface
Debugging is an important step in the
programming cycle.
One way to debug a program is to display
information about objects and variables
to ensure their validity.
9
Debugging an Interface
In the ball program, seeing information
about each of the objects as the
program runs is helpful.
Ball and Wall classes do not derive from
the same base class (Java does not
support multiple inheritance).
Ball and Wall can implement common
interfaces.
9
The Debuggable Interface
The Debuggable interface defines two
public methods:
displayStatus(String identifier);
displayError(String error);
The interface does not define how to
implement these methods.
Implementation details are left to the
classes.
9
Interfaces vs. Abstract Classes
Use an abstract base class if:
You are trying to create an is a
relationship:
A tree is a plant
A fly is an insect
You do not want to instantiate the base
class.
9
Interfaces vs. Abstract Classes
Use an interface if:
You are not trying to create an is a
relationship.
You are stating that your class has these
capabilities.
A Ball and a Wall have the capability of being
colorable and debuggable.
You need a way to handle multiple
inheritance.
9
Extending Interfaces
Interfaces can be extended just like
classes.
Allows the programmer to provide new
functionality without rewriting existing
code
Use the keyword extends: interface
DebugLogging extends Debuggable
9
Polymorphic Interfaces
Interfaces can be treated
polymorphically, as a type.
A method that accepts an object which
implements the Debuggable interface will
also accept any object which implements
any interface derived from the
Debuggable interface.

More Related Content

What's hot

Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Kostja Osipov
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)
Professor Lili Saghafi
 
Bt0082, visual basic
Bt0082, visual basicBt0082, visual basic
Bt0082, visual basic
smumbahelp
 
Lab13
Lab13Lab13
Behavioral design patterns presentation
Behavioral design patterns presentationBehavioral design patterns presentation
Behavioral design patterns presentation
Mina Ayoub
 
Total oop in c# dot net
Total oop in c# dot netTotal oop in c# dot net
Total oop in c# dot net
Muhammad Naveed
 
Analyzing Java Program
Analyzing Java Program Analyzing Java Program
Analyzing Java Program
cristy nazareno
 
Object Calisthenics in Objective-C
Object Calisthenics in Objective-CObject Calisthenics in Objective-C
Object Calisthenics in Objective-C
KLabCyscorpions-TechBlog
 
Design dimensions of DSLs
Design dimensions of DSLsDesign dimensions of DSLs
Design dimensions of DSLs
Mikhail Barash
 
computer programming and utilization
computer programming and utilization computer programming and utilization
computer programming and utilization
Kargathara Vishal
 
Java ocjp level_2
Java ocjp level_2Java ocjp level_2
Java ocjp level_2
Sayed Ahmed
 
JetBrains MPS: Typesystem Aspect
JetBrains MPS: Typesystem AspectJetBrains MPS: Typesystem Aspect
JetBrains MPS: Typesystem Aspect
Mikhail Barash
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
Lovely Professional University
 
From Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developerFrom Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developer
Katerina Trajchevska
 
13. interfaces
13. interfaces13. interfaces
13. interfaces
M H Buddhika Ariyaratne
 
Projectional editing
Projectional editingProjectional editing
Projectional editing
Mikhail Barash
 
Clean Code, Resumen Capítulo 1.
Clean Code, Resumen Capítulo 1. Clean Code, Resumen Capítulo 1.
Clean Code, Resumen Capítulo 1.
Francisco Lopez Espinosa
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.netilakkiya
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 

What's hot (20)

15 interfaces
15   interfaces15   interfaces
15 interfaces
 
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)
 
Bt0082, visual basic
Bt0082, visual basicBt0082, visual basic
Bt0082, visual basic
 
Lab13
Lab13Lab13
Lab13
 
Behavioral design patterns presentation
Behavioral design patterns presentationBehavioral design patterns presentation
Behavioral design patterns presentation
 
Total oop in c# dot net
Total oop in c# dot netTotal oop in c# dot net
Total oop in c# dot net
 
Analyzing Java Program
Analyzing Java Program Analyzing Java Program
Analyzing Java Program
 
Object Calisthenics in Objective-C
Object Calisthenics in Objective-CObject Calisthenics in Objective-C
Object Calisthenics in Objective-C
 
Design dimensions of DSLs
Design dimensions of DSLsDesign dimensions of DSLs
Design dimensions of DSLs
 
computer programming and utilization
computer programming and utilization computer programming and utilization
computer programming and utilization
 
Java ocjp level_2
Java ocjp level_2Java ocjp level_2
Java ocjp level_2
 
JetBrains MPS: Typesystem Aspect
JetBrains MPS: Typesystem AspectJetBrains MPS: Typesystem Aspect
JetBrains MPS: Typesystem Aspect
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
From Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developerFrom Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developer
 
13. interfaces
13. interfaces13. interfaces
13. interfaces
 
Projectional editing
Projectional editingProjectional editing
Projectional editing
 
Clean Code, Resumen Capítulo 1.
Clean Code, Resumen Capítulo 1. Clean Code, Resumen Capítulo 1.
Clean Code, Resumen Capítulo 1.
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.net
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 

Viewers also liked

Idea's1 only
Idea's1 onlyIdea's1 only
Idea's1 only
Graham Royce
 
Challenges
ChallengesChallenges
Challenges
Graham Royce
 
Managing A Start Up And Ethics M5
Managing A Start Up And Ethics M5Managing A Start Up And Ethics M5
Managing A Start Up And Ethics M5Graham Royce
 

Viewers also liked (6)

Chapter 01
Chapter 01Chapter 01
Chapter 01
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
 
Idea's1 only
Idea's1 onlyIdea's1 only
Idea's1 only
 
Challenges
ChallengesChallenges
Challenges
 
Managing A Start Up And Ethics M5
Managing A Start Up And Ethics M5Managing A Start Up And Ethics M5
Managing A Start Up And Ethics M5
 

Similar to Chapter 09

C# interview
C# interviewC# interview
C# interview
ajeesharakkal
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
talha ijaz
 
Inheritance in java.ppt
Inheritance in java.pptInheritance in java.ppt
Inheritance in java.ppt
SeethaDinesh
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
dheeraj_cse
 
Java interface
Java interfaceJava interface
Java interface
Arati Gadgil
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptx
ssuser84e52e
 
C# interview questions
C# interview questionsC# interview questions
C# interview questions
Chetan Chaudhari
 
C#
C#C#
Inheritance
InheritanceInheritance
Inheritance
Jaya Kumari
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in brief
DUONG Trong Tan
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
G C Reddy Technologies
 
Lecture 5 interface.pdf
Lecture  5 interface.pdfLecture  5 interface.pdf
Lecture 5 interface.pdf
AdilAijaz3
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developers
Sanjaya Prakash Pradhan
 

Similar to Chapter 09 (20)

C# interview
C# interviewC# interview
C# interview
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Inheritance in java.ppt
Inheritance in java.pptInheritance in java.ppt
Inheritance in java.ppt
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
Java interface
Java interfaceJava interface
Java interface
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptx
 
C# interview questions
C# interview questionsC# interview questions
C# interview questions
 
C#
C#C#
C#
 
Inheritance
InheritanceInheritance
Inheritance
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in brief
 
C sharp
C sharpC sharp
C sharp
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
 
Java 06
Java 06Java 06
Java 06
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Dtacs
DtacsDtacs
Dtacs
 
Lecture 5 interface.pdf
Lecture  5 interface.pdfLecture  5 interface.pdf
Lecture 5 interface.pdf
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developers
 

More from Graham Royce

Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
Graham Royce
 
My 3 min pitch pack
My 3 min pitch packMy 3 min pitch pack
My 3 min pitch pack
Graham Royce
 
Things to do
Things to doThings to do
Things to do
Graham Royce
 
House in order
House in orderHouse in order
House in order
Graham Royce
 
Blank 10 all you need
Blank 10 all you needBlank 10 all you need
Blank 10 all you need
Graham Royce
 

More from Graham Royce (20)

Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
Chapter 07
Chapter 07Chapter 07
Chapter 07
 
Chapter 06
Chapter 06Chapter 06
Chapter 06
 
Chapter 05
Chapter 05Chapter 05
Chapter 05
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 
Chapter 02
Chapter 02Chapter 02
Chapter 02
 
13 java in oracle
13 java in oracle13 java in oracle
13 java in oracle
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 
My 3 min pitch pack
My 3 min pitch packMy 3 min pitch pack
My 3 min pitch pack
 
Things to do
Things to doThings to do
Things to do
 
House in order
House in orderHouse in order
House in order
 
Blank 10 all you need
Blank 10 all you needBlank 10 all you need
Blank 10 all you need
 

Recently uploaded

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

Chapter 09

  • 2. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined methods. Each class implements the methods however it sees fit. A class can implement multiple interfaces.
  • 3. 9 Declaring the Interface Similar to a class declaration but uses the interface keyword The extends keyword can be used to extend interfaces.
  • 4. 9 Interface Restrictions Interfaces: Cannot have member fields Can define constants Cannot have methods with implementation; all methods in an interface are implicitly abstract Cannot be instantiated Cannot define constructors
  • 5. 9 Implementing Multiple Interfaces: The Debuggable Interface Debugging is an important step in the programming cycle. One way to debug a program is to display information about objects and variables to ensure their validity.
  • 6. 9 Debugging an Interface In the ball program, seeing information about each of the objects as the program runs is helpful. Ball and Wall classes do not derive from the same base class (Java does not support multiple inheritance). Ball and Wall can implement common interfaces.
  • 7. 9 The Debuggable Interface The Debuggable interface defines two public methods: displayStatus(String identifier); displayError(String error); The interface does not define how to implement these methods. Implementation details are left to the classes.
  • 8. 9 Interfaces vs. Abstract Classes Use an abstract base class if: You are trying to create an is a relationship: A tree is a plant A fly is an insect You do not want to instantiate the base class.
  • 9. 9 Interfaces vs. Abstract Classes Use an interface if: You are not trying to create an is a relationship. You are stating that your class has these capabilities. A Ball and a Wall have the capability of being colorable and debuggable. You need a way to handle multiple inheritance.
  • 10. 9 Extending Interfaces Interfaces can be extended just like classes. Allows the programmer to provide new functionality without rewriting existing code Use the keyword extends: interface DebugLogging extends Debuggable
  • 11. 9 Polymorphic Interfaces Interfaces can be treated polymorphically, as a type. A method that accepts an object which implements the Debuggable interface will also accept any object which implements any interface derived from the Debuggable interface.