Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes What is a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is a "first class collection"?" Watch "What is a "first class collection"?" New topic

What is a "first class collection"?

Stevens Miller

Joined: Jul 26, 2012
Posts: 863

I would like to do the Object Calisthenics exercise, which requires writing a thousand-line Java application in strict compliance with nine rules. Rule Four is this:
First class collections
Application of this rule is simple: any class that contains a collection should contain no other member variables. Each collection gets wrapped in its own class, so now behaviors related to the collection have a home. You may find that filters become a part of this new class. Also, your new class can handle activities like joining two groups together or applying a rule to each element of the group.

The body of the rule is easy enough to understand ("any class that contains a collection should contain no other member variables"), but what does "First Class collections" mean? Of course I've searched on this phrase, but most of what I'm finding seems to trace back to the Object Calisthenics exercise in some way, or to one of those questions you tend to find on stackoverflow that somehow goes kind of viral and ends up being repeated on a hundred different sites (probably because no one was able to answer it to the OP's satisfaction).

Wikipedia offers some help, but it doesn't really seem to relate to the body of the rule as written above.

What's a "first class collection" in Java?


In the other disciplines, we rise by standing on each others' shoulders. In computer science, we do it by standing on each others' toes.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
I don't think it means anything in Java. It's probably a term devised by the Object Calisthenics author. Or perhaps someone else. But regardless, there's no standard understanding of what the term is supposed to mean. Not in the mainstream Java community, anyway.
Stevens Miller

Joined: Jul 26, 2012
Posts: 863

Thanks, Mike. My impression is that you are correct. Kind of disappointing that they use it without explaining their meaning. I'll e-mail the authors and post any replies I get.
I agree. Here's the link:
subject: What is a "first class collection"?
It's not a secret anymore!