• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"OR operator" Design and Readability

 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 808
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic