• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to provide possible extension of Bean methods in the future  RSS feed

 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My task is to write EJB that provides simple calculating methods (e.g. add, subtract, divide) and remote web client that can choose any type of operation he wants. But also, I need to foresee possible addition of new methods in the future, not changing the bean class. What technology should I use for that (assuming I'm a newbie in java EE programing, I'm kind of confused)? Also, could you advise me whether I should use SLSB or SFSB?
Thanks in advance!
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still need your help, please. Sorry if the issue wasn't clearly described, but I'm ready to clarify it if you ask any questions.
Any help would be highly appreciated!
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37256
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anton,
What you are asking sounds impossible - how to change a class without changing a class? To elaborate, why do you want to not change the class? Why can't you create a new class? The answers to these will help uncover your needs which may lead to a solution.
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,
Thanks a lot for your reply. I know that it might sound ridiculous.
First of all, let me repeat my task. I need to provide an extension mechanism for list of EJB methods, not changing the bean class. That's one of a few tasks, that I was given on my job interview (so this is not my idea). Maybe it has something to do with putting some extra abstract methods into local/remote interface? Anyway, assuming the EJB has already been deployed, is there any way to update its methods, not having to deal with its bean class? I've never applied Java EE in practice, so I wonder how this (as I guess pretty common) task is done?
I'm eager to elaborate further on issue.
I appreciate your help very much.
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once again, the task is not to change a class without changing a class, but to provide extensibility mechanism (i.e. to provide an opportunity to add extra methods to already deployed EJB).
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anton Shaykin wrote:Once again, the task is not to change a class without changing a class, but to provide extensibility mechanism (i.e. to provide an opportunity to add extra methods to already deployed EJB).


Hi Anton..
As far as i know the only way to solve it is add new method to specific EJB class, and then redeploy it..
or perhaps, you could make new class and then extend the EJB existing class..
at this way you could override or add method that you want..

please correct me if i'm wrong..
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Leonardo,
Thanks for you response. I also thought that inheritance would probably be the only feasible solution. However I need to think more carefully about how I can automate process of adding new methods.
Again, any ideas would be greatly appreciated!
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but to provide extensibility mechanism (i.e. to provide an opportunity to add extra methods to already deployed EJB).


The client view of an EJB is the interface exposed by the EJB. So if you want to add extra methods then you for sure have to add new methods to the interface and then the bean implementation too will have to include these new methods.

 
Om Tejas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is other possible way to keep your interface unchanged. If I were you, I would have done this way:

My remote interface and its method will look like this:

interface WebOperationInterface {

public webOperations(String userOperation);

}

Now you can pass any operation you want is userOperation ("Add", "Substract", "log", "limit") etc..

Your bean class can implement the methods and in future if you require any more operations implemention , the implementation of bean class can be changed since bean is NOT directly exposed to client.

The idea is to make to make you remote interface methods as generic as possible.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Great Gaurav"

Please click on the "My Private Messages" link on top of this page, for one more message from JavaRanch.
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Jaikiran Pai:
Is there something wrong with the solution provided by Srivastava Gaurav? It looks quite logical.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anton Shaykin wrote:to Jaikiran Pai:
Is there something wrong with the solution provided by Srivastava Gaurav? It looks quite logical.


Nothing personal against Srivastava's - but in my opinion i don't think that suggestion is practical. Some of the reasons why i think it's not the right thing to do:

1) Even though you are not changing the signature of the method, you are still adding more responsibility to that method. Which means the clients of that method need to know this change.

2) Not all methods are like the one in that example, atleast in real world applications.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, why are you after such an exercise?
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:Again, why are you after such an exercise?

Well, originally it wasn't my idea. I was given this task at the job interview. So I've no idea why they would need such a feature. I thought it should be something common among Java EE Developers. But after it turned out that it's not I was curious about the way it's usually done in real world.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps they're looking for you to tell them it's not a good idea? Interviewers can be evil, after all
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!