• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

exchange if-elseif trees to ...

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im writing an application which can be configured with defined confiugrations (baseline) at the moment 5-8.
So some functions (for gui, check algorithms) have to do the processing in diffent way depending on the baseline. Not completly different but, slightly other.
Now we do this :

This is very hard to maintain...
So we want to change this to something more sofisticated.

Additional we sometimes have to handle fields for a baseline that do not exist in an earlier one.

I would appreciate any help with this topic

Thank you in advance
Mike
 
Marshal
Posts: 75874
361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the baselines into a Map as "K" and some sort of object which handles the differences as the "V"??
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or, define an interface that handles all the methods that are different across configs. Instantiate an object for the current baseline that provides the appropriate functionality for that baseline. The mainline code will not need to care which it is dealing with.
 
Mike Nightsky
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tanks.
@Champbell Ritchie
This would work fine for one occurence but there are about 100-150 Objects that need different handling for each and every baseline.
Different checking algorithms and additional different gui visibility.

@Bear Bibeault
Then the if-elseif tree just moved a bit, but still exists.
By the way this was how the old application was meant to be.
[ June 25, 2008: Message edited by: Mike Nightsky ]
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends greatly on what the "special handling" for each case is.

If you could show us a portion of actual code, we could better direct your refactoring efforts.
 
Bear Bibeault
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike Nightsky:
Then the if-elseif tree just moved a bit, but still exists.
By the way this was how the old application was meant to be.


Not really. I use this technique all the time with no else-if constructs. It's usually a matter of configuration and/or naming conventions.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chain-of-responsibility?

http://commons.apache.org/chain/
 
Mike Nightsky
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Bear Bibeault:
I have to decide which object to instantiate at runtime. Because, some times the baseline can change at runtime.

@Bill Shirley:
Sorry, i don't have an excample at hand now. But it's like checking ranges, and enum values.

@Vilmantas Baranauskas:
I will discuss this with the architects in the other teams at my company.

Thanks for your answers.
Mike Nightsky
 
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The if/else if/else if chain grows into a really long switch statement, and that's not good. You want to do something OO, like just do a polymorphic 'execute()' on a suitable object

Originally posted by Vilmantas Baranauskas:
Chain-of-responsibility?



Its a possibility, altho I really dislike tools that require two languages, in this case, Java + XML
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am wondering if Jess can be put to use here.

PS. From the website

Jess is a rule engine and scripting environment written entirely in Sun's Java language by Ernest Friedman-Hill...


This is the Ernest Friedman-Hill from the ranch?
 
Campbell Ritchie
Marshal
Posts: 75874
361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maneesh Godbole:
This is the Ernest Friedman-Hill from the ranch?

yes.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pat Farrell:

Its a possibility, altho I really dislike tools that require two languages, in this case, Java + XML



Who says that Chain Of Responsibility needs XML?
 
Mike Nightsky
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your thoughts and answers.

Our architects have some thing thought up with the command pattern. We give it a try in a prototype.
But a solution with a rules engine (Jess, JBPM) has not died completly.

Thank's for your help and keep up the good work you all do here!

Mike Nightsky
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic