Iterator
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.
As you may remember from the previous chapter, a squad consists of troopers or other squads. Let's create one now:
val platoon = Squad( Trooper(), Squad( Trooper(), ), Trooper(), Squad( Trooper(), Trooper(), ), Trooper() )
Here, we created a platoon that consists of four troopers in total.
It would be useful if we could print all the troopers in this platoon...