Canonicalise, Don't Remember — Smart Constructors in Kotlin

Story time! What follows is a slightly simplified and transposed-to-another-domain version of what I experienced this week. Ish.

In our app, we had a shopping cart (not really, though, but stay with me), where adding the same product twice should collapse into one line with the quantities summed. A colleague had recently shipped mergeBySku() to do exactly that. The “add to cart” code path called it. The “restore the user’s cart from the server” code path called it. Then a third construction site landed in the repo (someone’s “re-import items from a previous order” feature, or some such) without first making the call to normalise the line items. Then, lo and behold: a support ticket showed a customer’s cart with the same product appearing four times.

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论