© Edward Sciore 2019
Edward ScioreJava Program Designhttps://doi.org/10.1007/978-1-4842-4143-1_9

9. Composites

Edward Sciore1 
(1)
Newton, MA, USA
 

Chapter 8 examined decorators, which are wrappers that implement the same interface as the object they wrap. This chapter examines composite objects. A composite object is similar to a decorator except that it wraps multiple objects, each of which implements the same interface as itself. This seemingly small distinction makes a big difference in the structure of a composite and how it is used. Composite objects correspond to trees and composite methods tend to involve tree traversals.

This chapter presents three examples of composites: predicates, graphical user interfaces (GUIs), and cookbook recipes. These ...

Get Java Program Design: Principles, Polymorphism, and Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.