| Say you write some software that manages a shopping cart. a) You can "store" (even if it's in-memory) just the products and their quantities. Then each time you need to display the cart you go and compute the corresponding prices, taxes, discounts, whatever. b) You can store each cart line, whether it has discount(s) or not, as well as its taxes and the cart's global taxes and discounts and whatever else you can imagine. Option "b)" is probably more efficient (you are not constantly recomputing stuff) but you will be better off in the long term by going with option "a)": - Your cart management and your discount/tax computation are less coupled now (the cart doesn't really need to know anything about them) - You have less opportunities for miscalculation because everything is in one "logical flow" (computeDiscounts()/ computeTaxes()) instead of being scattered (some stuff is computed when you add an item or when you remove it, or when you change the quantity, or when you specify your location, etc..). The code will most probably just be simpler with option "b)". The article argues that you should sacrifice the performance in cases like this. I agree. |
Anyway I myself so wholeheartedly agree with the minimizing state idea.