• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I use a method in the class created from Class.forName  RSS feed

 
Pat Flickner
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, here's what's already being done:



This is causing an incredible amount of coding:



I want to have one set of code that does not require a bunch of if statements. Every time we add a new feature, I have to add it to the ever-lengthening list. I'm in the process of learning about patterns and I think this would apply, but right now, we're in crunch time and the only other way to "fix" this is to do the long list of "if" statements. I would love to do this:



Obviously, this cannot be done (I tried). I Googled a search as well, but no luck. Any clue or should I just -- for now -- continue appending to the list of "if" statements and set up a future design pattern? Thanks.

Pat
 
Jan Cumps
Bartender
Posts: 2632
17
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let all your services implement a common interface.

Let's say that they all implement MyService, having operation String getValue():

pseudocode:
Regards, Jan
[ March 19, 2007: Message edited by: Jan Cumps ]
 
Pat Flickner
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That'll work, but again, it's a ton of work because when this setup was created, I don't think anyone ever heard of consistency or standardization, so each one of these, although similar, has its own set of processes. Some of the processes are technically the same, but they're named differently. Totally stupid. I've just spent the past few days fixing code that was coded one way in one setup and another way in the other, yet both were expected to work exactly the same way. I have about 15 classes that I have to look at. I feel like I'm in Mudville and my predecessors were Casey.

Thanks.
 
Jan Cumps
Bartender
Posts: 2632
17
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You 're out of luck.
If there is no consistency in the code, you will have to use IFs, or build the consistency yourself. Work to be done in in both cases.
If you go for introducing consistency, future service classes can integrate with your code. If you're going for the IFs, you will have to keep growing the condition list.

If you can't touch the service classes, you can use the Gang of Four's Adapter pattern to morph the services to comply to an interface.
Use the Adapter pattern when
  • you want to use an existing class, and its interface does not match the one you need....
  • Regards, Jan
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!