Composite
You may finish this section with a lingering feeling that this pattern is a bit awkward. That's because it has a soul mate, it's accompanying pattern, Iterator, which we'll discuss in the next chapter. When both are combined, that's where they really shine. So, if you're feeling confused, come back to this pattern after you have got acquainted with Iterator too.
Having said that, we can start analyzing this pattern. It may look a bit strange to have a Composite design pattern. After all, aren't all Structural Patterns about composing objects?
Much like in the case of the Bridge design pattern, the name may not reflect its true benefits.
Get together
Going back to our strategy game, we have a new concept: a squad. A squad consists of zero or more infantry units. This would be a good example of a somewhat complex data structure.
Here are the interfaces and classes we have:
interface InfantryUnit class Rifleman : InfantryUnit class Sniper : InfantryUnit
How would you implement that? We...