Commit

b02a8dc

am i crazy or are #php backed enums the factory pattern with a little extra spice? i think i would be displeased by prefixing my factories with the enum keyword though. anyone do this? tell me more.
Well, it makes sense that you’d see it that way because of the superficial similarity, but be careful, there’s a trap here, and it’s to confuse syntactic convenience with architecture. Ultimately, a backed enum lets you do something like…
Over time, this tends to lead to other problems: - It can violate the Single Responsibility Principle (SRP) because it shifts from representing a type or state to dictating how things are constructed. - You start with a small match and end up accumulating labels, rules, etc. - Testing the code that calls it is more difficult because it’s not as straightforward to isolate or mock. Where I really think they’re useful is at the boundaries, for type-safe serialization and deserialization, and for identity specific aspects of use cases that don’t change based on the environment. Things like readable labels, colors, or badges; state transition rules; lightweight VOs; and so on. I see them more as typed key-value maps, super useful for passing to a real factory, rather than a factory itself

commit b02a8dc

i knew it smelled funny! this is excellent insight, thank you! i already didn't like the lack of a constructor. MOST of my factories are static and almost never have setup code in the cases. i try to ensure that all my factories return 1 interface and all classes share the same…