Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Pattern »

Re: Business Delegate v/s Session Facade

Bill Dudney

2003-09-08

Replies:

Hi All,

Hi Alok_Band,

First I'd like to say, don't build an MVC framework for the web without
looking at, Struts, WebWorks, Tapestry, JSF, etc. (no order or slight
against other frameworks intended :-). There are many available so
please make sure to check them out before you build your own, unless of
course you have a great new idea and want to open source it so we can
all benefit! :-)

OK, that being said the typical MVC framework for the web implements
some sort of command pattern so that all you really have to write is
the code that invokes the 'back end' logic. The Web Tier view of the
back end logic is embodied in the Biz Delegate. So from the perspective
of the web tier the business logic looks like what the Biz Delegate
presents. With that in place your web tier is free to evolve in
whatever direction it needs to as long as the action/information it
needs are available through the delegate.

From the back end as long as the Biz Delegate is able to fulfill its
API there is great flexibility to evolve as well. In a way the Biz
Delegate(s) lay out the responsibility the back end has to the web tier.

The separation of the two tiers in my mind is the major benefit of the
Biz Delegate pattern. You have a very nice clean separation of your
Model and View. Both sides of the application can evolve quite a bit
without needing the other side to know about the changes.

The Service Locator pattern lets your web tier code be free from
knowledge of the complexity of service lookup via JNDI. I almost always
use these two patterns in conjunction with each other, the Biz Delegate
asks the Service Locator for all EJB Sessions or other JNDI available
resources before it does its work.

Both patterns provide isolation for your web tier code, but for very
different reasons.

TTFN,

-bd-
http://bill.dudney.net

On Saturday, September 6, 2003, at 05:17 AM, Maciek Żywno wrote:

> Alok_Band wrote:
>
>> Hi Maciek,
>>
>> Thank for reply. I am an early bird in J2EE patterns. Please clarify
>> my
>> doubts.
>>
>>     So what is business delegate about?
>>     - tt hides from a client all complexity connected with network
>> calls,
>>     i.e. a client invokes some method on a delegate which is a
>> normal
>> java
>>     object, and delegate uses lookup services to find a target
>> session
>> facade
>>
>> Look up services are best addressed by "Service Locator" pattern.
>> Service
>> Locator will contain code look up any services(like JNDI lookup and
>> creation
>> of remote for session facade) so should one still use Business
>> Delegate if
>> "Service Locator" is used?
>>

>>     - it can catch "network" exceptions and show a client
>> "business"
>>     exceptions so that a client e.g. does not have to know anything
>> about
>>     the service distribution
>>
>> Consider MVC application, should not Servlet convert network
>> exception in
>> user understandable message instead of adding one more layer. Even if
>> Business Delegate throws any "business (Application)" exception
>> servlet
>> would still have to catch it and display it to user.

>>
>> Thanks and Regards,
>> Alok
>>
>>
>>
> Hi Alok
>
> As I understand it, a business delegate uses lookup services to locate
> a
> service. Any client(e.g. a servlet) uses a business delegate as an
> additional layer to "connect" to services layer. A client doesn't know
> what lookup services a business delegate uses, actually it does not
> know anything about lookup services.
>
> >>Even if Business Delegate throws any "business (Application)"
> exception servlet would still have to catch it and display it to user.
> Yes, but in this case servlet does have to catch
> "SeriousNetworkException" but only "BusinessServiceUnavailable"
> exception generated by a business delegate.
>
> When business delegates catches a network exception it can try to
> connect once again to session facade. It can use a lookup service once
> again on its own, while a servlet does not what is happening in the
> background. Obviously there must be some critical point when a business
> delegate throws a kind of "service unavailable" exception to a servlet.
>
> I can imagine that a business delegate and service loacator
> functionality is in the same class. But I think that each kind of
> client
> should have its own kind of delegate and maybe all those delegates
> should use the same service locator. So there may be a reason why a
> business delegate and a service locator functionality should not be in
> the same class (i.e. possible duplication of code).
>
> That's how I understand the problem.
> Someone else, please, comment on the problem?
>
> Regards
>
> Maciek Zywno
>
> ====================================================================
> Companion Site: http://www.corej2eepatterns.com
> J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
> List Archive:
> http://archives.java.sun.com/archives/j2eepatterns-interest.html
> Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to
> listserv@(protected)
>

====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.