# Composite: Boxes Inside Boxes

When the tracker weighs a shipment by asking every item "are you a box or a pallet?", it needs one more nested loop for every level of pallets, and a pallet on a pallet on a pallet gets missed; with the Composite pattern, a box and a pallet answer the same question, and a pallet answers by asking what's on it.

![Cheat sheet: Composite: Boxes Inside Boxes](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/5d8655f078af4ed6b6a25096101cf2c5.webp)

- Category: Data Structures
- Level: Journeyman
- Tags: Composite Pattern, Decorator Pattern, OOP, Recursion, Tree
- Author: Gregor Dzierzon
- Updated: November 17, 2026

Source: https://www.ask-codey.com/cheat-sheets/dp-composite-cheat-sheet
