I\'m working on a small game written in Java (but the question is language-agnostic). Since I wanted to explore various design patterns, I got hung up on the Composite pattern/E
Ents seems to be designed to do exactly what you want. If you still want your own library, you could at least learn from its design.
The previous answers all seem clunky and create tons of unnecessary objects, IMO.