Commit

4c38484

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. -…
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 constructor arguments. so far, i'm just using enums to wrangle long lists of class/interface constants that are getting used haphazardly (if at all) across logic. it's really nice to get rid of literal string comparisons. sometimes these consts weren't even used for that. i had one class where, after refactoring consts to an enum, there are 27 usages. that's a lot of places to remember to update strings like 'Y' and 'N'. yikes! 😬

commit 4c38484