Subj : Re: Polymorphism sucks [Was: Paradigms which way to go?] To : comp.programming,comp.object From : Michael Feathers Date : Sat Jul 09 2005 08:06 pm >>>I suspect in part it is because trees can be well-represented visually >>>such that the primary pattern is easy to discern. I say "primary" >>>because trees often visually over-emphasis one or few factors at the >>>expense of others. >> >>You make a lot of statements you don't support with examples. Can you >>provide an example of this happening? > > > Here is an example borrowed from c2.com. We taxonomize drinks by making > each orthogonal factor a level: > > DRINKS > > > Coke > --Diet > ----Caffeinated > ----No Caffeine > --Regular > ----Caffeinated > ----No Caffeine > Lemon-Lime soda > --Diet > ----Caffeinated > ----No Caffeine > --Regular > ----Caffeinated > ----No Caffeine > Iced Tea > --Diet > ----Caffeinated > ----No Caffeine > --Regular > ----Caffeinated > ----No Caffeine > > Any one of the three factors (flavor, dietness, caffeiness) could be > put at the top level, but we cannot put them all there. Thus, we must > make one the "king" arbitrarily and demoting one arbitrarily to the > leaves. Why not? You can have three hierarchies: flavor, caffeination, sweetening. You make a drink by composing them: Drink drink = new Drink(); drink.addFlavor(new Cola()); drink.addCaffeination(new TenPercentCaffeination()); drink.addSweetening(new Diet()); Adding a fourth factor only impacts the Drink class, and you can create new types of, say, Sweetening and make arbitrary drinks with them: drink.addFlavor(new GrapeFruit()); // yeech! drink.addSweetening(new Splenda()); The problem is that you only see one tree. You can have as many as you want and that is what makes OO design resilient to change. No, if all you see is one tree, no wonder you think OO is for the birds. Michael Feathers author, Working Effectively with Legacy Code (Prentice Hall 2005) www.objectmentor.com .