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.We use backed enums with a
handler(): PaymentDriver method using app()->make(...) for stateless strategy resolution, and it's super clean until a driver needs request-scoped constructor args.I don't see the problem if it's for creating simple instances. For example, I've used it for deciding which event to fire.
But for factories with a lot of decency injections I'd stick to a proper factory.
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…