Breaking Up a God Enum
One ItemAction enum had grown to 44 cases covering every domain in the game, and every new feature bolted on another. How it got split into eleven focused enums behind a shared contract, with an architecture test that stops it from ever quietly reassembling.
Listening · Breaking Up a God Enum
Enums are supposed to be small. This one wasn't. On IcePets, a single ItemAction enum had accumulated 44 cases spanning every corner of the game, inventory actions, gallery actions, shop actions, pet actions, all of it, in one list. And it only ever grew, because every new feature had exactly one obvious place to add its action: the bottom of the pile.
The reviewer note, which was me, was blunt. This is going to keep expanding forever. Each section should own its own set of actions, and there should be an architecture test that fails the moment two sets collide. That's the whole project in one comment, and the shape of the fix is worth walking through, because a god enum is just a god object wearing a smaller hat.
Why one big enum rots
The problem isn't the size on its own. It's what the size does. A 44-case enum spanning every domain is a thing that every domain depends on, which means every domain is coupled to every other domain's actions through a shared list none of them owns. Add a case for shops and you've touched the file that inventory, gallery, and pets all import. There's no boundary, no ownership, and no force resisting growth. It's a junk drawer with a type.
The tell is exactly the one the reviewer flagged: you can feel it will only ever get bigger, because there's no smaller place for anything to go.
Eleven enums behind one contract
The split gives each section its own enum, eleven of them, one per domain. But eleven enums are only useful if callers can still treat "an item action" as one uniform thing, so each enum implements a shared contract, in this case a small interface with two methods: a label() and a component(). A caller doesn't care whether it's holding a storage action or a gallery action. It's holding something that satisfies the contract, and it asks the contract what it needs.
The one piece that requires thought is turning a raw string, the value that arrives from the API or comes out of the database, back into the right case, now that there are eleven possible homes instead of one. So there's a resolver: hand it a raw string, and it finds which set owns that value and returns the matching case. Callers go through the resolver, depend on the contract, and never touch the eleven concrete enums directly. The monster is gone and nothing downstream noticed it left.
The test that keeps it split
Here's the part that makes the split durable instead of temporary. Eleven independent enums could, over time, drift into overlapping, two sets both defining a value like open, and now the resolver has an ambiguous answer and you're quietly back in a mess. So an architecture test asserts that no two sets share a value. It runs in CI, and the day someone reintroduces a collision, the build tells them, not a confused user three weeks later.
The test does have to enumerate the sets to compare them, and there's more than one way to do that. I used a reflection-based class finder, which walks the classes and picks out the enum sets. An explicit registry, a plain list the resolver and the test both read from, is another way, trading the reflection for a little manual bookkeeping. Reflection-based discovery isn't the default Laravel reaches for and it isn't free at runtime, but it's a perfectly legitimate approach, and either one gives you the same guarantee: no two sets can share a value without the build noticing.
Why this is the shape to reach for
Put together, it's the standard cure for any god object. Split the one thing everything depends on into focused pieces that each have an owner. Give them a shared contract so callers stay uniform. Add a resolver for the one place that has to bridge between the raw world and the typed one. And enforce the boundary with a test, because a boundary nobody checks is a boundary that erodes.
Adding a new section's actions is now a new enum in that section, touching nobody else's, and the arch test guarantees it can't collide with what's already there. "Just one more case" can't rebuild the monster, because there's no longer a single pile to add it to.
The split itself was the easy, satisfying part. Actually moving the 44 existing usages across the codebase to their new homes is where it got exciting, and briefly disastrous, but that's its own story.