The Composite Pattern has two variations:
- The abstract Component (parent class of leafs and composites) only includes methods that make sense on a single item.
- The abstract Component also includes the methods of the Composite, i.e. of a collection of items.
Remember that the purpose of the composite pattern is to treat single items and collections of such items in an uniform way. Given an appropriate structure, the composite methods can be implemented in a way that have some meaning even on leafs. E.g. in the context of the DOM, a text node has no childs, and can return an empty NodeList.
This 2nd variation of the Composite pattern isn't always applicable, but it can increase the elegance of the design in some cases (I would still have designed the DOM without this quirk).