When we were discussing the Composite design pattern in the previous chapter, we noted that the design pattern felt a bit incomplete. Now is the time to reunite the twins separated at birth. Much like Arnold Schwarzenegger and Danny DeVito, they're very different, but complement each other well.
Iterator
One, two... many
We're back to our squads and platoons in our CatsCraft 2: Revenge of the Dogs strategy game.
As you may remember from the previous chapter, Squad consists of InfantryUnits:
interface InfantryUnit
class Squad(val infantryUnits: MutableList<InfantryUnit> = mutableListOf()) {
}
Each squad should also get a commander now.
The commander of a squad called Sergeant is also an InfantryUnit...