aspose file tools*
The moose likes Java in General and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark ""OR operator" Design and Readability" Watch ""OR operator" Design and Readability" New topic
Author

"OR operator" Design and Readability

Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
Please find the attached situation where i have used OR operator. Is it correct way to implement such situation?



What is alternative to do this thing?

Don't want to use switch-case, as in that i have to take a variable and jumpings in cases, add more variables and may be function or could i use it more suitably how?
and am i doing above is correct? as it harms readability


Regards
Azrael Noor
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

Firstly, I would create a method returning a boolean to evaluate the condition, just to improve readability.

Secondly, I'd be tempted to put the values you test for into a set and use Set.contains() for the test. Either use a HashSet, putting values to it in upper case and upper-casing the value to be tested too, or use a case-insensitive set, that is a TreeSet with case insensitive string comparator (ie. String.CASE_INSENSITIVE_ORDER).
Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
Ok Lets take this




as the situation going here is



What you saying will benificial here?

and where will you make set? in class where i am using this or where from i accessing using objWSClientManagement?

This will confused and on wrong contains() call will let intrude the control in wrong method?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Azrael Noor wrote:Ok Lets take this
...
What you saying will benificial here?

Ah, changing the rules now. Not quite kosher


and where will you make set? in class where i am using this or where from i accessing using objWSClientManagement?

wherever you want

This will confused and on wrong contains() call will let intrude the control in wrong method?

I don't see why. Seems like a very sensible suggestion to me.

An alternative might be something like:(I leave the details to you)
then in your code:however, it's still quite a mouthful, and I actually think that Martin's suggestion is more generic.

My suggestion: step back from the code for a minute, and try to work out exactly what these enormous if statements are doing.
It seems to me that you're stuck in a rut of thinking like a coder, not a designer.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Without knowing any details (as you have supplied none) I would say that perhaps all this decision making ought to happen in objWSClientManagement. It looks as if you are trying to operate a car by standing outside and reaching in through the window, when the best place to control a car is from inside the car.
Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
Without knowing any details (as you have supplied none) I would say that perhaps all this decision making ought to happen in objWSClientManagement. It looks as if you are trying to operate a car by standing outside and reaching in through the window, when the best place to control a car is from inside the car.


You can say

as in OBJWSClientManagement, we have different operations defined.

To check event and pass the control over different opoerations is done in class told above.

For different ecents we have different objWS


So for each web service we have class, and calling depend on partucular events which are
defined in Web Service classes and those events are related to that particular web service only.

like obhClientManagement will handle YO MO KO LO CHAKO
like objOrganization will handle YO MO sho jo

so flow like


hope it helps!!!
please suggest
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2393
    
  28

I would use strategy pattern that is driven by a rules file. So, let's say you had an EventHandler interface, and you have various implementations (one for objWSClientManagement operation, one for objWSOrganization operations, one for objWSPersons). Then you can have a rules file that describes what events can occur, and which EventHandlers should be call for that event. Your main event handling method simply looks up the rules file to find all the event handlers for the event, and calls them.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Azrael Noor wrote:So for each web service we have class, and calling depend on partucular events which are
defined in Web Service classes and those events are related to that particular web service only.

Personally, I like Jayesh's suggestion (gave him a gold star); but one other possibility suggests itself from your description:
Have each "Handler" class contain a set of the Events it handles and simply have the manager class hand off the event off to each one in turn.

If the handler "knows" the event, it deals with it (that might be a little trickier to do without writing dispatch code, but I suspect it could be dealt with by an enum); otherwise it does nothing.
It also allows for the fact that (as per your example) an Event can be processed by more than one Handler.

I suspect both solutions have "incompleteness" issues (ie, an Event that no handler knows about), but being an old fart I kind of prefer that to be the responsibility of a developer rather than a "configurator".
But in these JEE days it seems XML rules...or is that XML rules rule...I forget...

Winston
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2393
    
  28

Thanks Winston. I like your design which is more like a Chain of Responsibility pattern. Each handler processes the event and passes it to the next handler. If a handler doesn't want to process the event, it just passes it to the next handler. + for you too


If you want to reduce the amount of coding, you can use annotations. So, your handler looks like this



This way you don't have repeated code in each handler for checking the events. You can just process the annotations to create a proxy that injects the code for checking the events and calling the real handle method if it matches.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Jayesh A Lalwani wrote:If you want to reduce the amount of coding, you can use annotations. So, your handler looks like this...

Blimey. 2 gold stars. Are you bucking for a Nobel Prize?

Winston
Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
Never Implemented concept of Handler in VAST. I have used Handler in getting Web Service Response.

Handler is used which is like this:


For that XML Configuration is used, and SAR file is deployed in JBOSS



This is not invoked by Main and invoked internally.

I do not know how to invoke myself? simply make object of class?

Any tutorial regarding this?
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2393
    
  28

Azrael,

You are getting confused between Command Pattern and SoapHandlers. One is a design pattern, the other is an interface that is designed using the pattern. SoapHandlers are handlers but they aren't the only handlers. They are just an example of an handler. What we are telling you here is that you might be able to improve your design if you design your own handlers

IMO, at this point, what you need to do is first understand the Command, Strategy and Chain Of Responsibility design patterns. The past few posts will make a lot more sense once you understand those design patterns.
Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
Found Following patterns:



Studying!!!

I am not following any thing out of it. It's all AZRAEL PATTERN

Will ask you if have any problem, and thank you for showing me the way
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "OR operator" Design and Readability