Use First-Class Collections
Any class containing a collection should have no other member variables — wrapping collections gives filtering, sorting, and rules a semantic and cohesive home.
Why this matters
When a plain list is passed around, every caller invents its own way to filter, sort, or query it. The same for user in users if user.is_admin loop ends up in five different files. Wrapping the collection in a class with named methods means that logic exists exactly once — and the name makes the intent obvious.
Code Challenge
Study the messy code, try to refactor it, then reveal the clean version.
💡Key takeaway
Any time you pass a raw list or array, ask: does this collection have behaviour that's repeated in more than one place? If yes, it deserves its own class with a meaningful name and focused methods.
🔧 Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it — it helps us fix it fast.
Hint: If you're filtering or sorting a list in more than one place, the list needs to become a class with those behaviors built in.
✗ Your version