• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EPractice Lab Question regarding Business Delegation

 
Ray Ye
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, I am preparing to be re-certified with OCMJEE6 and

Here is a question from EPractice Lab which they allow me to post here since I don't agree with their provided answer

Java EE Business Delegate patterns refers to which OO design approach
A. Separation of Concerns
B. Delegation
C. Encapsulation
D. Abstraction

Here is the quote from Oracle's Core J2EE Pattern, http://www.oracle.com/technetwork/java/businessdelegate-137562.html

Use a Business Delegate to reduce coupling between presentation-tier clients and business services. The Business Delegate hides the underlying implementation details of the business service, such as lookup and access details of the EJB architecture.

The Business Delegate acts as a client-side business abstraction; it provides an abstraction for, and thus hides, the implementation of the business services.

So it is a bit of everything here. But I think the main intention of BD is to hide the underlying implementation details to access EJB service. So I opt for C. The provided answer is B which I think it is just means of implementation details.

What is your opinions?

Thank you and Best Regards,
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A business delegate class is what the client knows but does not in itself encapsulate the implementation of the business logic. The business logic is implemented by a class (or classes) that the client does not know about. The job of the BusinessDelegate is to delegate calls from the client to the actual class(es) that implement the business services. The information that the delegate hides is not the implementation details of the service (that is just a consequential plus) but rather the identity of the service classes and how they are invoked.
 
Ray Ye
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I did not say BD encapsulate business logic. It encapsulates the access to business service. And it is not simple delegation, it needs service locator to look up, and it may need to handle exception and retry access, etc. It may do a lot more than just delegation. But it encapsulates all these details to the client.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray Ye wrote:And it is not simple delegation, it needs service locator to look up, and it may need to handle exception and retry access, etc. It may do a lot more than just delegation. But it encapsulates all these details to the client.

It MAY do all those extras but that's not its intended job. If you don't use a ServiceLocator in the BusinessDelegate and don't handle exceptions or do retries you still have a valid business delegate. As long as it delegates the calls from the client to the service classes it has already done its job as a business delegate. Many JEE patterns are implemented in one class making it difficult to accurately divide the intention of each pattern. The exam expects you to be able to pick out what exactly matches a pattern and what are extra side effects that typically arise when the pattern is applied.
 
Ray Ye
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have to look at the intention of the design pattern. A lot of design patterns are using delegation, e.g., Wrapper (Object Adaptor), Chain of Responsibilites etc. Delegation itself is not the intention it is means of design/implementation. E.g. Favor object composition over class inheritance, in Gof Design Pattern book. Composition will always use delegation. So what is delegation? According to Design Patterns definition,

delegation
An implementation mechanism in which an object forwards or delegates a request to another object. The delegate carries out the request on behalf of the original object.


So it is an implementation mechanism. Not the purpose. We don't do delegation for the sake of delegation.

Back to Business Delegation, sure it does use delegation, but it is not the purpose. The purpose/intention is to encapsulate the EJB class from details of looking up/accessing EJB business service. This is also explained in Oracle's website (and book) Core J2EE Patterns regarding BD,

"The Business Delegate hides the underlying implementation details of the business service, such as lookup and access details of the EJB architecture. "
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray Ye wrote: The purpose/intention is to encapsulate the EJB class from details of looking up/accessing EJB business service. This is also explained in Oracle's website (and book) Core J2EE Patterns regarding BD,
No that is the purpose of a ServiceLocator not a business delegate. The main purpose of a business delegate is to decouple the client layer from the service layer.

 
Ray Ye
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The Business Delegate hides the underlying implementation details of the business service, such as lookup and access details of the EJB architecture. "

This is quoted from Oracle not me, if you don't agree with the official resource of the pattern.

Even as you said, "The main purpose of a business delegate is to decouple the client layer from the service layer", then BD is not for just delegation (and again I agree it uses delegation), it provides abstraction and encapsulation for business service components (EJBs).
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way you are applying your reasoning, why don't use this statement
it provides abstraction and encapsulation for business service components (EJBs)
to chose the answer as D:Abstraction?

Does encapsulation require a business delegate to be implemented?

One last time, the main point of the delegate is not to hide who the service layer is not how it is implemented or accessed. Those are just side benefits possible based on how the delegate is implemented. A business delegate that simply passes through calls to the real services is still a valid delegate even if it has the exact same signature as the service classes. It still does it's job of decoupling the client classes from the service classes.

It seems unlikely that we are going to agree here. Anyhow, good luck with your preparations.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic