Remember: The interface is wholly interface-independent. No constructor, no fields, no comments about any implementation details.
Interface:
// "T" is a generic type parameter
// - (So the bag can store any type of object)
public interface BagInterface<T> {
int getCurrentSize();
boolean isEmpty();
boolean add(T newEntry);
boolean remove();
boolean remove(T anEntry);
void clear();
getFrequencyOf(T anEntry);
integer boolean contains(T anEntry);
[] toArray();
T}
Implementation:
public class Coin implements BagInterface {
// we'll cover implementation after learning generics
}
Client:
public class PiggyBank {
private BagInterface<Coin> coins;
public PiggyBank() {
this.coins = new Bag<>();
}
public boolean add(Coin aCoin) {
return coins.add(aCoin):
}
public Coin remove() {
return coins.remove();
}
public boolean isEmpty() {
return coins.isEmpty();
}
}
Example Use:
public class Client {
public static void main(String[] args) {
= new PiggyBank();
PiggyBank bank }
}
public interface SetInterface<T> {
int getCurrentSize();
boolean isEmpty();
boolean add (T newEntry);
boolean remove (T anEntry);
remove();
T void clear();
boolean contains(T anEntry);
[] toArray();
T// etc...
}