Commit

7586f44

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
php
PaymentMethod::from(‘stripe’)->createProcessor()
And in the moment, it’s convenient, you’ve saved yourself the trouble of using a factory. But if you push it too far, you turn it into a glorified primitive type and end up using it everywhere. If you start instantiating services or heavy classes inside it, you end up introducing dependencies into layers that should be pure. Plus, enum methods don’t have constructors with dependency injection; as soon as you need to pass a service, you have to set it up manually with new or pass weird parameters, bypassing the container. (Continued in my next reply)

commit 7586f44

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. -…