/*******************************************************************************
* Companion code for the book "Introduction to Software Design with Java",
* 2nd edition by Martin P. Robillard.
*
* Copyright (C) 2022 by Martin P. Robillard
*
* This code is licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* See http://creativecommons.org/licenses/by-nc-nd/4.0/
*
*******************************************************************************/
package e2.chapter3;
/**
* Represents an entity from which it is possible to obtain cards.
*/
public CardSource {
/**
* Returns a card from the source.
*
* @return The next available card.
* @pre !isEmpty()
*/
Card draw();
/**
* @return True if there is no card in the source.
*/
boolean isEmpty();
}
As mentioned in the Card
example, methods in interfaces are implicitly public
,
even if the keyword public
is omitted.
As mentioned in the Card
example, methods in interfaces are implicitly public
,
even if the keyword public
is omitted.
As mentioned in the Card
example, methods in interfaces are implicitly public
,
even if the keyword public
is omitted.
As mentioned in the Card
example, methods in interfaces are implicitly public
,
even if the keyword public
is omitted.
The ability to have different shapes.
The ability to have different shapes.
The goal of an interface is to specify what services (that is, methods) objects of a certain class should have, without committing to a given implementation of these services. Programming with interfaces allows , because different classes can provide different variations of the required behavior.
Chapter 3, insight #1
Use interface types to decouple a specification from its implementation if you plan to have different implementations of that specification as part of your design
The goal of an interface is to specify what services (that is, methods) objects of a certain class should have, without committing to a given implementation of these services. Programming with interfaces allows , because different classes can provide different variations of the required behavior.
Chapter 3, insight #1
Use interface types to decouple a specification from its implementation if you plan to have different implementations of that specification as part of your design