What it is good for

The composite design pattern is useful for reducing code duplication and simplification when we create hierarchies. The simplification part comes from the fact that clients do not need to know which type of objects they are dealing with. Adding new types of nodes is also easy and won't make us change anything else.

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.