Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to design the EJB method related to several operations?

 
Along huang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me illustrate, for the user-register function, here are two kinds of EJB design mode:

1. the EJB has three business methods,
A) isExistUserName()
B) isUserInBlacklist()
C) register()
first of all, client invoke isExistUserName() to check if the user name already exist, then invoke isUserInBlacklist() to check if the user is on the blacklist, finnaly, client invokde register() to register.

2. the EJB have only a method named register()
client directly invoke register() to register, the method register() throws two exceptions:
A)UserExistException: it means the user name exist
B)UserInBlacklistException: it means the user is in the blacklist

To solution 1, client interact with EJB serveral times, so it consume a lot of net resource. To solution 2, client only access EJB one time, but it is hard to process to client program.

Do you think which solution is better?
Any suggestion is appreciative.

best regards
 
Deepak Pant
Ranch Hand
Posts: 446
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go for solution 2 as it is close to SessionFacade and ApplicationService design pattern.

The client should pass all the elements required for processing the request, the Facade or ApplicationService should validate and process the use case specific request.

Going by this logic pick option 2.
 
Along huang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for reply.

In solution 2, exception class will increase rapidly, such as UserExistException and UserInBlacklistException.
It is the reason why I can't make decision to select soluion 1 or 2.

best regards
 
Deepak Pant
Ranch Hand
Posts: 446
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create one generic BusinessException class which contains error code or message specific to the error.
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Deepak Pant:
You can create one generic BusinessException class which contains error code or message specific to the error.


I'm no J2EE expert, but error codes are usually viewed as "anathema". Note that Java exceptions do not include an error code even though they include a text message and another exception.

If all the exceptions result in the same behaviour when they occur, I'd use one BusinessException with specific messages.

if there is ever a reason to treat them differently I'd go for a BusinessException and several subclasses that define the specific exceptions .
 
Deepak Pant
Ranch Hand
Posts: 446
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter - you make a valid point.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic