I think this is better seen than expained.
Examples:
public class AttackCommand implements Command {}...
public class DefendCommand implements Command {}...
....
let's say we wanted to add these to a common list of commands. Then you could add these to the list below.
(in a new class)
public ArrayList<Command> commands = new ArrayList();
public CommandManager() {
commands.add(new AttackCommand());
commands.add(new DefendCommand());
}
Now here is where that supposed reference comes in. What if we wanted to get a list of the command by name (pretending command has a getName method), or the last attacked target via AttackCommand (pretending it has a LastAttacked method)?.
public void printNames() {
for (Command cmd : commands) {
System.out.println(cmd.getName());
}
}
public Entity getLastAttackTarget() {
for (Command cmd : commands) {
if (cmd instanceof AttackCommand) {
return cmd.lastAttacked();
}
}
}
(I know that a map of the commands to just grab by name would be better, but for the sake of the example....)
In essence, it's a better general reference to all things that inherit the interface, but not the interface itself.