Re: Refactoring to Strategy: What happens with Conditional Logic?
Joshua Kerievsky <[email protected]> Sun, 28 Nov 2010 07:23:08 -0800
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Nov 22, 2010 at 7:29 AM, katerinaxristopoulou < [email protected]> wrote: > I have recently read "Refactoring to Patterns" by J.Kerievsky and I have a > question regarding "Refactoring Conditional Logic with Strategy". I really > don't understand what happens with conditional logic and how it is > eliminated. I feel like the conditional logic is somehow moved to the client > rather than being eliminated, but i'm not sure about that cause then, the > problem with complicated conitional logic still remains. > > What's your opinion? Is it more clear for someone else? > Hello Katerina, Sorry for the delay in responding - I was on vacation. You are not alone in asking the above question. I should have been more clear about that in the book. It is correct that we don't want to just push the conditional logic to the client. Instead, we'd like to handle the selection of which strategy to use without relying on conditional logic. Imagine that we have a collection of specification classes, each of which knows about the exact loan criteria that would equate to a match with a given loan. For example, say that one spec class would look for loans that have an expiry date, no maturity date and an "unused" percentage that is not 100%. If an instance of that spec matches the data in a given loan instance, we have a match and can then configure the Loan with the correct strategy instance. Does that help? What I'm describing is really an example of the Specification pattern, described in Domain-Driven Design as well as in my book, under the refactoring called Replace Implicit Language with Interpreter - http://www.industriallogic.com/xp/refactoring/implicitLanguageWithInterpreter.html . -- best, jk -- Joshua Kerievsky Founder, CEO Industrial Logic, Inc. Web: http://industriallogic.com Twitter: @JoshuaKerievsky, @IndustrialLogic Amplify Your Agility Coaching | Training | Assessment | eLearning [Non-text portions of this message have been removed] ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/refactoring/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/refactoring/join (Yahoo! ID required) <*> To change settings via email: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/