3 ms·
Avoid Putting Logic in Map Blocks
- galaxyLogic 3y agoAnother way of putting this would be: "Make map() statements as simple as possible by adding methods to the objects being mapped over". This makes sense except when the elements being mapped over are built-in and library-types which you can not add methods to. But in that case I would suggest add the methods to the class containing the mapping-code.
- sammygadd 3y agoIn the first example it seems obvious that that logic belongs in Item. But for the coupon stuff, that doesn't fell 100% right either. IMHO Coupon should be the one that knows how to calculate item costs, items should know nothing about coupons. (The discount calculation seems to have a typo. It looks like it calculates the discount rather than the price after discount)