| ▲ | another_twist an hour ago | |
That blog post is a poor example. It replaced a simple straightforward if-else loop with a hard to understand abstraction spaghetti. A few unit tests and you'd be well on your way to shipping rather than messing around with beautiful patterns. | ||
| ▲ | sedatk 27 minutes ago | parent [-] | |
Obviously, because it was a fictional, simplified example for the post. My real use case was more complicated and involved multiple developers working on different parts of that flow. The problem with if-else chains is it's easy for a programmer to forget to handle a case that another developer added in the called component. Unit tests can't help a spec miscommunication. But, visitor pattern can as it forces the handling logic to be complete. Hence my example at the end using discriminated unions and exhaustive pattern matching in F#. Much, much simpler with the same benefits. | ||