Skip to main content
7 events
when toggle format what by license comment
Jun 12, 2020 at 6:47 comment added Christophe I'm not worried about the language issue. But if one has a hammer in the hand, every problem looks like a nail, and I wondered if this nice solution addresses the roots of the issue.
Jun 12, 2020 at 6:24 comment added wasatz @Christophe As mentioned even if your language doesnt have this feature you can implement this pattern as a library. However that isnt as nice as having it as a language feature ofc.
Jun 12, 2020 at 6:17 comment added Christophe Isn’t this question more related to the architectural pattern than to the language?
Jun 12, 2020 at 6:06 comment added anon Interesting. I hadn't seen that. I suppose if it comes to it, I may implement the version I mentioned in my previous comment. It seemed to me that this must be a solved problem I wasn't aware of, which I suppose you say it is, just not in all languages. I'm probably being too particular. "The perfect is the enemy of the good" after all.
Jun 12, 2020 at 5:58 comment added wasatz @AgentConundrum There seems to be an RFC for union types in PHP wiki.php.net/rfc/union_types_v2 that is hopefully part of PHP8 if I read this correctly? That seems like exactly the language feature that you could leverage to solve this cleanly. But if I read this correctly then PHP8 is slated for release in november so right this day you would probably have to implement a "poor mans version" of this yourself if you wanna go this direction.
Jun 12, 2020 at 5:52 comment added anon I intentionally didn't mention a language as I hoped this to be a general purpose/best practices question, In my case, my project is in PHP as it's the language I know best right now. There, I do have the option to return whatever type I like, though I wouldn't be able to type hint it. I could try to make #3 cleaner by having the factories return a ValidationObject from #2 which includes a third member/getter for the validated object (i.e. ValObj.IsValid, ValObj.GetErrors, ValObj.GetValidatedObject). Admittedly, I'm just theory-crafting right now. I haven't got myself into trouble in code yet.
Jun 12, 2020 at 5:33 history answered wasatz CC BY-SA 4.0