"The ThoughtWorks Anthology" - Jeff Bay (2008)
Objects Calisthenics:
- Rule #4: First Class Collections
This rule specifies that any class containing a collection should not have any other member variables. It emphasizing that each collection deserves its own dedicated home (class).
Such encapsulation turns collections into first-class citizens within the domain, providing a clear home for behaviors related to the collection, such as filtering, aggregation, or applying rules to each element.
Wrapping collections thus not only gives them a more defined structural role in the domain, but also elevates domain-specific concepts, making collections integral and well-defined components of your software's architecture.
This principle is akin to wrapping primitives, but specifically tailored for collections, ensuring that behaviors have a designated home and that collections are treated with the same care and consideration as other domain-specific elements.