This is review. Work in groups.
Each person works the exercise individually.
Then the group compares solutions. If solutions differ, discuss with the goal of convergence.
remove()
method
in the java.util.List
interface:
public boolean remove(E e)
Note: Ignore the fact that List
is a subtype of Collection
.
In other words, write the contract "from scratch".
java.util.Set
interface
remove()
method,
determine whether there is a subtype relationship between List
and Set
.
Be very specific about the steps in your analysis.
List
a subtype of Comparable
?
Why or why not?
What about String
?
Chooser
class.
Suppose we allowed Chooser
objects to be empty.
What would this mean for the contract of the choose()
method?
Specifically, write two contracts for choose()
, one that treats this case
with a precondition, and the other that treats this case with a postcondition.
What is the (possible) subtype relationship between these two Chooser
classes?
Chooser
class that allows adding an additional choice
beyond what is supplied to the constructor.
public void addChoice(E choice)Write a contract for this method and implement it.
Write a client interaction that starts with three of four card suits
(CLUBS, DIAMONDS, HEARTS),
and later adds SPADES.
Choose something from the 4 suited Chooser
object.
Suppose we decide Chooser
objects should be immutable.
What should we do with the addChoice()
method?
What happens to the client interaction with the suits?