Hehe, that looks like Lisp!
I can't think of a good pattern that would be applicable here at this
moment. However, I would suggest to do some little steps in order to
enhance the code.
First, I would try to break that single condition statement into nested
conditions. This is as bad as having such a long statement, but has the
benefit that, if you group the nested conditional statements by
function or source class, you might be able to identify higher-level
conditions that might be refactored. For instance, consider this simple
statement:
if (!file.exists() || (file.exists() && !file.hasWritePermission()))
return false;
can be re-structured as:
if (!file.exists())
return false;
else
if (!file.hasWritePermission())
return false;
There it's easier to notice that you might move that to another function, name
it file.isWrittable()
Of course, the first thing to consider when one sees such long
statements is to break them into smaller ones and keep small
intermediate values to keep things clearer. Those smaller statements
are often candidates to be refactored into different methods. In your
case, this might be an approach:
bool temp1, temp2, temp3;
temp1 = cCall.hasLockingCondition() || getUtility().usesConfig() ;
temp2 = getUtility().externalWriteUtility() || (!call.hasParameters());
temp3 = call.isNothingReturned() && (!call.shouldBuildObject()) &&
(!call.isWriteRequired());
if (temp1 && temp2
&& temp3)
...
I can't help with the names as I don't really know the meaning and
context of the methods, and of course some Boole's algebra would help a
lot re-structuring that, but it's really late here and I don't feel
like thinking that.
In any case, hope this helps you figure a solution out. Good luck!
Regards,
Jesús
Date: Wed, 14 Nov 2007 18:36:07 -0800
From: [EMAIL PROTECTED]
To: [email protected]
Subject: [patterns-discussion] Design pattern recommendation
Hello to all the four who replied (I guess a Gang of Four did reply to my
message!!)
Thanks for all the suggestions. I will certainly look at all of them closely.
Though it looks I may need the State pattern. I will also buy that book that
was recommended.
In any case here is the code thats hard to read
Basically thats the code that I am trying to refactor ( I have relabeled the
methods )
if (call.isNothingReturned() && (cCall.hasLockingCondition() ||
getUtility().usesConfig() )
&& (!call.shouldBuildObject()) &&
(getUtility().externalWriteUtility() || (!call.hasParameters())) &&
(!call.isWriteRequired()))
Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/_______________________________________________
patterns-discussion mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/patterns-discussion