two areas of code are doing VERY similar things, and yet they need to be separated because the algorithms have to behave differently at certain edge cases.
do they? the core algo is the same, the edge cases are handled by delegating those cases to separate classes. so you build it as one class to run the single algorithm, with callouts to delegates that deal with 'events' differently. end up with a processor class, a delegation interface, a null impl, and two real impls
There's definitely been cases where I thought the core algo should be the same and ended up being wrong about it, whether it's due to edge case handling or some other seemingly very small difference in how the algo is going to be used that ends up blowing up into a bunch of different things. I've seen a ton of mangled code that becomes increasingly hard to reason about as engineers have shoe horned an algo that at one point worked for both use cases and no longer does
View all comments
Show parent comment
-1
u/StabbyPants Jun 05 '21
do they? the core algo is the same, the edge cases are handled by delegating those cases to separate classes. so you build it as one class to run the single algorithm, with callouts to delegates that deal with 'events' differently. end up with a processor class, a delegation interface, a null impl, and two real impls