Search the web
Sign In
New User? Sign Up
testdrivendevelopment · Test-driven Development
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Uploaded File: "2007-11-18 - Refactoring Challenge - LogicMatrix.zip   Message List  
Reply | Forward Message #26550 of 32000 |
I just uploaded a "refactoring challenge" file, in Java, with JUnit
tests: "2007-11-18 - Refactoring Challenge - LogicMatrix.zip"

If there a good way to express this code in Java:

public class LogicMatrix {
. public static void callTheRightMethod(boolean a, boolean b, boolean
c, boolean d, Interface callback) {
. . // TODO: Refactor this to be simple and obvious:
. . if (!a && !b && !c && !d)
. . . callback.x();
. . else if (a && !b && !c && !d)
. . . callback.z();
. . else if (!a && b && !c && !d)
. . . callback.w();
. . else if (a && b && !c && !d)
. . . callback.w();
. . else if (!a && !b && c && !d)
. . . callback.x();
. . else if (a && !b && c && !d)
. . . callback.x();
. . else if (!a && b && c && !d)
. . . callback.z();
. . else if (a && b && c && !d)
. . . callback.w();
. . else if (!a && !b && !c && d)
. . . callback.y();
. . else if (a && !b && !c && d)
. . . callback.x();
. . else if (!a && b && !c && d)
. . . callback.x();
. . else if (a && b && !c && d)
. . . callback.z();
. . else if (!a && !b && c && d)
. . . callback.y();
. . else if (a && !b && c && d)
. . . callback.y();
. . else if (!a && b && c && d)
. . . callback.x();
. . else if (a && b && c && d)
. . . callback.x();
. }
}

to be a bit more like the decision matrix that generated it...
= "XZWW"
+ "XXZW"
+ "YXXZ"
+ "YYXX";
without lots of reflection or other icky stuff? ;->

(This relates to the "If-else or DecisionMaker -- Fizz-Buzz Test"
thread --
http://tech.groups.yahoo.com/group/testdrivendevelopment/message/26540
)




Sun Nov 18, 2007 11:16 pm

jeffgrigg63132
Offline Offline
Send Email Send Email

Forward
Message #26550 of 32000 |
Expand Messages Author Sort by Date

I just uploaded a "refactoring challenge" file, in Java, with JUnit tests: "2007-11-18 - Refactoring Challenge - LogicMatrix.zip" If there a good way to...
Jeff Grigg
jeffgrigg63132
Offline Send Email
Nov 18, 2007
11:16 pm

... P.S. The point being that if we had a good way to do this in our language(s) of choice, then we'd have addressed the "If-else or DecisionMaker" thread's...
Jeff Grigg
jeffgrigg63132
Offline Send Email
Nov 18, 2007
11:18 pm

I played a bit with this. I didn't think yahoo would deal with the code well (I've had bad experience with that...), so I posted it at my recently created...
Donald Roby
donalroby
Offline Send Email
Nov 19, 2007
4:43 am

Hey its done before I even read it. My 2c.. Lose the boolean params - it took me a minute to figure what was goin on. I would use a straight hash Cur Inputs...
Gishu Pillai
gishu_pillai
Offline Send Email
Nov 19, 2007
5:35 am

As I wait for my almighty C++ super solution to build... I was curious as to how it would turn up in Ruby. I don't know how Java would simulate passing around...
Gishu Pillai
gishu_pillai
Offline Send Email
Nov 19, 2007
9:00 am

... curious as to ... passing ... Java would simulate passing around code blocks using inner classes. It's a bit more verbose... -- Don Roby ...
Donald Roby
donalroby
Offline Send Email
Nov 20, 2007
2:43 am

... Good response. Certainly valid. My intention was running more towards existing and proposed language features that could be used to simplify the logic....
Jeff Grigg
jeffgrigg63132
Offline Send Email
Nov 26, 2007
3:05 am

... Well, that does simplify . if ((a && !b && !c && !d) || (!a && b && c && !d) . . . || (a && b && !c && d)) . . callback.z(); to . if ((a && !c && !d) || (b...
Jeff Grigg
jeffgrigg63132
Offline Send Email
Nov 26, 2007
3:18 am

... Yes, this is sort of a metaprogramming approach, moving toward a DSL. But a matrix similar to this is a common way of representing this kind of decision,...
Donald Roby
donalroby
Offline Send Email
Nov 27, 2007
3:30 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help