Collections are all too often seen as simple bags full of some particular type of objects. These collections are then at the mercy of their clients. They get taken apart, have elements added and removed, iterated over, and just plain trampled upon. They are given no responsibility of their own.
It is time for that to change! Collections are people too!
Collections represent important concepts in a domain – concepts that appear over and over again as you build different features in your application. They can enforce constraints and provide many operations that apply to entire sets, lists, or maps of domain objects. Creating custom collections (they do not even have to be part of the Java Collections framework!) gives a home for these collection manipulation concepts. Without this home, you would have to remember to include, and rebuild, the constraints or operations every time you built a feature that involved the collection.
Today I created
IDSNumbers to act as a home for operations that we often perform on sets of
IDSNumber, particularly in our overly-complex calculation code. So far it just has a
sum method, but as I (hopefully we) find other common operations, it will be picking up more abilities that we can apply across all our applications.
What other collections are there that deserve to become citizens in their own right?