Is the Business Delegate a Singleton?

I use the Business Delegate to hide the implementation details (lookup, EJB, etc.) of the Business Service from the client. The same Business Delegate is used in many different places in the client. Now I would like to avoid to pass around the object reference of the Business Delegate in the client.
I wonder if the Business Delegate should be a Singleton. Is this reasonable?
Thank you.

excellent, thanks for your comments.
so to the orginal question, would you agree with the comments below?
The pattern catalog describes the business delegate as containing an instance of an EJBObject where as the service locator can optionally cache an EJBHome object. The former avoids repeated JNDI lookups and creating an EJB whilst the later just avoids repeated JNDI lookups.
Using this strategy, the delegate looks up the home interface and creates an instance of an EJB on creation; it has a one-to-one relationship with it. You don�t really want the delegate to have to create an EJB from the home interface in every method so it should therefore contain an instance member.
This all means the delegate can�t be a singleton, it can't share that EJBObject with multiple clients.

Similar Messages

  • The business delegate pattern in petstore

    hello
    who can tell me which class in the petstore implement the business delegate pattern.
    otherwise,who can tell me which website provide sample code for the j2ee design psttern.
    thank you very much!

    Session beans are usually an application of a Business Delegate pattern.
    Web Browserable source
    http://java.sun.com/blueprints/code/jps131/src/index.html
    Other J2ee stuff.
    http://java.sun.com/blueprints/code/jps131/docs/index.html

  • === SESSION FACADE v/s BUSINESS DELEGATE ===

    Hi
    Can anyone help me with my design here - I am not sure whether to use a Session Facade or a Business Delegate in the following scenario:
    [Our application is pure J2EE and does not use EJBs]
    PRESENTATION-TIER
    I have a Command and Control strategy employed in my presentation tier where requests are intercepted by a controller and processed by helpers delegating to appropriate commands and dispatch appropriate responses.
    PRESENTATION-TIER - COMMANDS
    The Commands will invoke appropriate Business Methods in the business tier to retrieve data (mostly).
    BUSINESS-TIER
    Now - most of my business methods use the DAO pattern to retrieve data and are effectively dealing with Data Beans (Value Object beans) - passing them back to commands.
    I can clearly see the use of a generic Interface at the Business tier - i.e., rather than expose the Buiness Methods direcly leading to increased coupling between presentation and business tiers.
    BUT THE CONFUSING PART IS - DO I USE A SESSION FACADE OR A BUSINESS DELEGATE TO INTERFACE WITH MY COMMANDS??? What is the difference? I have looked at Sun's J2EE blueprint and cant make out the clear cut difference between the two.
    Can anyone help?
    thanks
    Aswin

    I agree with you, Business delegate and Session facade are quite alike.
    I believe that you could use the Business delegate pattern as a facade. Possibly, you could argue that the Business delegate is an extension of the Session facade pattern. However, I think that SUN thinks that a Business delegate should be a singleton while a Session facade is a session EJB. My firm belief is that you could create a business delegate that is a session EJB instead.
    But, you could also use both pattern as some one else suggested.
    In your case when you do not use EJBs, I would suggest that you use a facade which could be design like a business delegate. However, as there aren't any EJBs, you will not need a service locator. In this way, you will have a design that can be extended (without any impact on the the presentation tier) to use EJBs in the future.
    Remember, SUN's core J2EE patterns assume that you use EJBs. If you don't, they have to be adapter a little bit.

  • Business Delegate Pattern?

    What is the real use of Business Delegate pattern in a J2EE architecture design?
    I know it is to decouple the Presentation and Business Logic tiers. But all I can see is it just contains one method which basically accepts data (say Value Object) from Presentation tier (in an example I am looking, it is a Command class) in a method and the method in turn just calls a Session Facade Bean from the Model tier. So, why do we need a Business Delegate class in this scenario? And what are the drawbacks of calling the Session Facade Bean directly from the Command class?
    Thanks for helping me understand it better.
    Rgds,
    Tappori

    Business delegate typically is a presentation-tier object. It serves to shield the presentation-tier from business-tier implementation details. A Business Delegate can encapsulate business services from one or many Session Facade and could also delegate processing to web services as well.
    Here are some fancy links that talk about the Business Delegate guy-
    http://forum.java.sun.com/thread.jsp?forum=425&thread=535855
    http://forum.java.sun.com/thread.jsp?forum=425&thread=548634
    http://forum.java.sun.com/thread.jsp?forum=425&thread=523520
    http://forum.java.sun.com/thread.jsp?forum=425&thread=495578
    And what are the drawbacks of calling the Session Facade Bean directly from the Command class?You tie the presenation-tier object (Command) to business-tier implementation. The Command class should not have lookup code in it and it should not know that it is calling a remote object. Say you want to replace the EJB implementation with the XYZ implementation. Would you then have to recompile all of the Command classes and/or subclasses?

  • Business Delegate and Session Facade usage.

    Hi guys.
    I am new to JavaEE and I recently learnt the Business Delegate and Session Facade design patterns. The tutorials from Oracle did gave me a basic idea of what they are and why they are used, but the example didn't really answer all my questions. So I decided to use a real life scenario here and put my question in to it. Any help is appreciated.
    Assume I want to create a search employee page for my company, the employees are categorized by his or her department and the province he or she is in. I have in the database a look up table for department and province. (as shown in the image below)
    http://oi46.tinypic.com/idvpsl.jpg
    So I create three JPA entities, one for each table. Now I am stuck with what is the proper way to design the session facade design pattern. I know that I will need the to access all three entities in my page. (to get the drop down list for Provinces and Departments, and to retrieve list of Employees based on the selection) So should I create a Stateless Session Bean as session facade to access all three JPA Entities or should I create three separate Stateless Session Bean to manage one Entity each?
    I came up three component diagram in the below picture.
    The first one has one Stateless Session Bean as session facade and manages all three Entities.
    The second one has a session facade to manage the relationship between business objects such as ProvinceManagerEJB and DepartmentManagerEJB which will manage the corresponding Entities.
    The last one has three Stateless Session Beans that will manage one Entity each, all three Stateless Session Beans can be looked up via the Business Delegate pattern.
    http://oi46.tinypic.com/10pqets.jpg
    Please let me know if any one of them is the proper way to use business delegate and session facade. or none of them is correct. (which I assume might happen)
    Again, thank you so much for your help.
    Cheers
    Edited by: 992005 on 05-Mar-2013 18:15
    Edited by: 992005 on 05-Mar-2013 18:17

    Well I can't access any of your diagrams from here so can't comment on them. For dividing the functionality into separate classes, think about
    1.) Quantity - Are there many enough service calls to require splitting up or will one application service class be enough? The size of the system is important here.
    2.) Are you duplicating logic in the services? e.g save person, delete person in one service and save department, delete department in another e.t.c is better factored into one service with save entity, delete entity calls because the JPA entity manager doesn't know about the type anyway and it's easier to apply common logic (e.g logging auditing) around the calls.
    3.) Will each service makes sense on it's own or do you always need the other functionality to completely describe the service? Here it is important not think about entities but about the business use cases. Process1Service is better than Entity1Service, Entity2Service ... EntitynService.Think granule of reuse = granule of release. Only split out individually reusable services. A good way to understand granules of reuse in your system is to think about (or start by writing) test cases for the functionality. Testable code is reusable code.
    4.) Will the services change together? At class level you would look at common closure principle (classes that change together should be packaged together). You can apply the closure to the methods as well. Make it easy for future developers to recognize dependent functionality by packaging it together.
    These are just general because in enterprise development requirements are king. You can chose to follow or discard any of these rules depending on your requirements as long you understand the impact of each decision.

  • Business Delegate, Session Facade or both?

    Hi,
    I'm having some problems with figuring out the point of using both Business Delegate (BD) and Session Facade (SF). As far as I can see, you often have a 1-1 mapping between the BD and SF, so why not use the SF directly?
    Here's my scenario. I have a web application that uses WebWork for presentation and pageflow, a session facade implemented using an ejb, which aggregates calls to the businness objects into "business rule"-methods and business objects implemented using plain java objects. Is there really any need to have a business delegate here? I might as well use the session facade directly from the webwork actions? Or..?
    Any suggestions? Am I far off? ;-)

    As far as I can see, you often have a 1-1 mapping between the BD and SF, so why not use the SFYou can have one Business Delegate encapsulate all of the business methods that are exposed by one or more Session Facades. The benefit here is that you protect the web component from any details of the business tier. e.g. your business tier has five session facades and the web tier has a single Business Delegate. The BD can be extended to call web services as well.
    Here's my scenario. I have a web application that uses
    WebWork for presentation and pageflow, a session
    facade implemented using an ejb, which aggregates
    calls to the businness objects into "business
    rule"-methods and business objects implemented using
    plain java objects. Say you eliminate the EJB implementation. What effect will this have on the web tier objects? The Business Delegate will enable you to easily replace the business implementation with little impact on the web components.

  • Difference between session facade and business delegate patterns

    Hi,
    How the session facade and business delegate patterns differ from each other, as both of them have similar and almost same forces to be addressed.
    Please address.
    Satya.

    BTW, in J2EE Core patterns :
    When the Business Delegate is udes with a Session Facade, typically there is a one-to-one relationship between the two. This one-to-one relationship exists because logic that might have been encapsulated in a Business Delegate relating to its interaction with multiple business services (creating a one-to-many relationship) will often be factored back into a Session Facade.[I/]

  • Diferences between Business Delegate and Session Facade

    Hi, I've been programming with java for a long time now, but recently decided to formally studing the J2EE patterns. By now I have the intuition of many of them but in paper looks a little confusing. Let me ask you what is a clear diference between Business Delegate and Session Facade.
    For me, exposing interfaces, hiding implementations and masking the complex interactions in the back are common factors in these patterns, could you please help me to identify diferences?

    There are more subtle differences, but the basic gyst is that the Business Delegate is used on the client/presentation tier. The Session Facade is used on the server/service tier. The Business Delegate typically performs a lookup of the SessionFacade which in turn fronts a service method (EJB or otherwise). The Business Delegate pattern is typically associated with J2EE remoting and its shortcomings.
    - Saish

  • Business delegate

    I hope this topic isn't completely worn out ... I tried looking a bit for
    relevant info here.
    I'm looking at mixing and matching an EJB deployment with local and remote
    interfaces. The Business Delegate pattern seems the way to go. Here, we can
    encapsulate and logic around the selection of a remote or local
    implementation for example (and among other things).
    The rub seems that we would like to define an interface that mostly
    defines our basic business contract. Of course (or maybe not - I know I will
    get some dissention here), this interface should not throw RemoteException.
    We can have our remote interface extend this interface and define the
    methods WITH a throws RemoteException clause. Our local interface may just
    extend this one. But, the container won't let us do this. It wants our
    interface to throw Remote.
    I tried defining a new EJB, as opposed to the one EJB deployed with both
    interfaces - that didn't work. I've headr it suggested that the uber
    interface be defined with a throws Exception clause, but this really breaks
    the contract.
    I think you get the picture. I'm sure that by now there are some good
    solutions to this. I am interested to hear them.
    Thanks for your input.

    Well I can't access any of your diagrams from here so can't comment on them. For dividing the functionality into separate classes, think about
    1.) Quantity - Are there many enough service calls to require splitting up or will one application service class be enough? The size of the system is important here.
    2.) Are you duplicating logic in the services? e.g save person, delete person in one service and save department, delete department in another e.t.c is better factored into one service with save entity, delete entity calls because the JPA entity manager doesn't know about the type anyway and it's easier to apply common logic (e.g logging auditing) around the calls.
    3.) Will each service makes sense on it's own or do you always need the other functionality to completely describe the service? Here it is important not think about entities but about the business use cases. Process1Service is better than Entity1Service, Entity2Service ... EntitynService.Think granule of reuse = granule of release. Only split out individually reusable services. A good way to understand granules of reuse in your system is to think about (or start by writing) test cases for the functionality. Testable code is reusable code.
    4.) Will the services change together? At class level you would look at common closure principle (classes that change together should be packaged together). You can apply the closure to the methods as well. Make it easy for future developers to recognize dependent functionality by packaging it together.
    These are just general because in enterprise development requirements are king. You can chose to follow or discard any of these rules depending on your requirements as long you understand the impact of each decision.

  • Business Delegate pattern - need some advice

    Hi. First let me apologize for the long post. I could see no other way. I�m building a system that quite large and I need some advice. The system is a type of transaction system, let�s suppose a shopping cart. I�m using struts taglibs and tiles for presentation, struts proper for controller, and POJOs for business logic. Also I�m using OJB for my data tier.
    Now I�ve been reading Pro Jakarta Struts (Apress), which BTW is a recommended read to anyone with novice experience in struts and related technologies. I�ve assimilated most of the techniques and patterns described in the book, and most of them make sense to me. However, I�ve hit a snag while reading the Business Delegate and Service Locator patterns.
    The way I had though of building my application before reading the book, was to have a wrapper class, such as the following:
    public class ShoppingCart {
      private IAuthenticationService authenticationService;
      private ITransactionService transactionService;
      public ShoppingCart() {
         authenticationService = new DBAuthenticationService();
         authenticationService = new DBTransactionService();
      public login(String username, String password) {
         String sessionToken = authenticationService.logon(username, password);
         return sessionToken;
      private boolean isValidUser(sessionToken) {
         bolean validUser =  authenticationService.isValidUser(sessionToken);
         return validUser;
      public performTransaction(sessionToken, TransactionVO) {
         if (!isValidUser(sessionToken) {
              throw new AuthenticationException();
         transcationService.performTransaction(TransactionVO);
      public editPreferences(sessionToken, PreferencesVO) {
         if (!isValidUser(sessionToken) {
              throw new AuthenticationException();
         authenticationService.performTransaction(PreferencesVO);
    }My idea was that my wrapper class would isolate all the business logic and could perform login service in case my application was ever to be used with other presentation layer than struts (standalone client, web services). However I believe that this overlaps the Business Delegate pattern and maybe even totally implements it. The way I understand the code I�m reading in the book, they suggest having a BD for each major service such as AuthenticationServiceBD, TransactionServiceBD, etc� However this would break my single point of entry for authenticating users. I really need some advice on my design and how it fits with the BD and SL patterns (or others). I would also like to know what you think/recommend of my authentication strategy.
    thanks in advance
    Raphael

    Thanks for your reply. This however, I understood. My concern is regarding my application in regards to business delegate pattern. You see I have this class (simplified for clarity):
    public class ShoppingCart {
       private ILoginService ls = new DBLoginService();
       private ITransactionService ts = new DBTransService();
       // and so on for all services I offer.
       //  then I mirror all the calls of my private interfaces
       //  and pass them through internally
       public String sessionToken login(String username, String password) {
            ls.login(username, password);
       public boolean addToCart(sessionToken, itemNo) {
            // check session
            ts.addToCart(sessionToken, itemNo);
       //  and so on
    }Multiple questions for this one:
    1) Am I not already implementing the Business Delegate pattern with my ShoppingCart class since all interfaces are private and all calls are mirrored from the wrapper class (ShoppingCart) to the private interfaces? All services are implemented as POJOs and I am not using JNDI at the present so I don't use the ServiceLocator pattern.
    2) I store a reference to the wrapper class (ShoppingCart) in the ServletContext so I can grab it from my Action classes. What do you think of this approach?
    3) How many BDs should an application contain. In my case I use just one. What is the advantage of using more?
    4) I create my own session tokens in case I ever want to use to business code in a non-web applications where sessions are not available readily. This brings about the problem that I can't pass the interfaces directly to the Action classes because the login session needs to be checked before any calls to services. So all methods include a sessionToken parameter which I use to check the session. This way, if I want to expose some of the services through web services, I can still use a login. What do you think of this approach.
    5) Any other remarks are very welcome...
    I really need help with this from an experienced programmer. Most things I can handle on my own but with this type of design issue, books just don't cut it. I need experience. I would really apreciate some feedback.
    Raphael
    ps: I would give all my Duke dollars for this (I only have 30), but I'm not sure how. If you want them I can create a dummy question and give them to you.

  • Business Delegate (remove session bean)

    HI all,
    I followed the code example of Business Delegate pattern
    as described in java.sun.com site.
    Everything is well, but I have only a doubt:
    in Business Delegate's constructor the Business Delegate object
    create the session bean reference that it will use.
    I don't see any call to session.remove() method.
    Is it a forgetfulness or there is no real need to call the remove method ?
    May developers rely on the Application Server for bean's removal ?
    (removal for Statfeul or pooling for Stateless)
    Many thanks in advance
    Moreno

    Yes, it's fine to rely on the ejb container to remove both stateful session bean and stateless session bean resources. Most ejb containers define a timeout period after which stateful session beans that have not been accessed will be removed. Similar settings typically control the amount of time a stateless session bean instance will be pooled within the container.
    If you'd like more predictable, programmatic control for stateful session bean removal, you can explicitly call EJBObject.remove(). In that case, the ejb container is required to call ejbRemove on the corresponding stateful session bean, assuming it hasn't already been removed. For stateless session beans, EJBObject.remove() is merely a hint to the container, and might not result in any specific action on the pooled instances. Hope this helps.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Business Delegate and Service Locator

    Hi all,
    I read the Business Delegate Pattern
    and my question is about how many Business Delegate
    I must write:
    a) one for every Session Beans ?
    (in a Session Facade Pattern)
    b) one for all Session Beans ?
    Is it right that I must have a single Business Delegate
    and different Service Locators if I need to
    call the same EJBs deployed inside different Application Servers ?
    Many thanks in advance,
    Moreno

    Please explaine your Question in more Detail?

  • Difference between Proxy pattern and Business Delegate pattern

    Hi All,
    Can any one please tell me what is the difference between Proxy pattern and Business Delegate pattern.
    Thanks in advance.
    Basak

    The books they were first reported in, and the expressed intent, I guess. Arguably, the Business Delegate pattern is a special case Proxy, with more specific details about what resource is being proxied

  • Business delegate pattern doubt

    Hi,
    One of the reasons for going for Business delegate pattern is because the business components is vulnerable to changes.
    Suppose if the business component has a method
    getAccountInfo( int Accountnumber)
    The business delegate pattern may have a method
    getAccountInfoFromBusiness(Accountnumber int)
    return businesscomponent.getAccountInfo(Accountnumber);
    and the presentation tier components will have code containing invoking to getAccountInfoFromBusiness method.
    Now suppose if business component method signature changes then the signature of business delegate class will also change. This turn in requires changes to presentation tier components. I really dont understand why business delegate pattern is needed.

    Hi,
    One of the reasons for going for Business delegate
    pattern is because the business components is
    vulnerable to changes.Abstraction is your first tool to reduce a projects exposure to change.
    Secondly filling you code with getter and setters is a bad idea, it's procedural not OO, Objects should express themselves.
    So instead of :
    Suppose if the business component has a method
    getAccountInfo( int Accountnumber)consider
         Account account = getAccount( AccountID accountID ) ;          // or
         Account account = findAccount( AccountName accountName ) ;
         ... AccountInfo = account.toString( FULL ) ;          // or
         ... AccountSummary = account.toString( SUMMARY ) ;     // or
         ... AccountBalance = account.balance() ;This abstracts the Account's identification, from an int, makes your code robust to change, and more flexible, and easier to understand.
    The business delegate pattern may have a methodThis is not good, the naming is particularly specific and relies on assumptions about the architecture, it looks like a a global function, yet should be a method of businesscomponent, which is also badly named.
    getAccountInfoFromBusiness(Accountnumber int)
              return businesscomponent.getAccountInfo(Accountnumber);
    }Instead consider the following. I've used abstraction to hide the implementation details, and the relations model real life, and I can handle my objects polymorphically.
         class Account { ... }
         class DayBook {
              Hashtable accounts ;
              public Account getAccount( AccountID accountID )
                   accounts.get( AccountID accountID )
         class MyApp
              DayBook salesDayBook = new DayBook() ;
              DayBook purchaseDayBook = new DayBook() ;
              Account account = salesDayBook.getAccount( theAccID ) ;
              Account account = purchaseDayBook.getAccount( theAccID ) ;
              }Here DayBook is a collection of Accounts, I've two instances, one for my sales one for my purchases.
    and the presentation tier components will have code
    containing invoking to getAccountInfoFromBusiness
    method.
    Now suppose if business component method signature
    changes then the signature of business delegate class
    will also change. This turn in requires changes to
    presentation tier components. I really dont understand
    why business delegate pattern is needed.The Business Delegate is not really a pattern as such, it is an appliction of the Proxy pattern abstracted into Business language/terminology.

  • Implement business delegate as a singleton.

    Anyone have any comments regarding implementing the bussiness delegate
    as a singleton? I currently have something like this.
    public class ClientUserManager {
    public ClientUserManager() {
    public void deleteUser(Long userid) throws RemoteException,
    CreateException {
    UserManagerHome umh =
    (UserManagerHome)EJBHomeFactory.getInstance().getBeanHome(Constants.USERMANAGER_CLASS,
    Constants.USERMANAGER_JNDI);
    UserManager um = umh.create();
    um.deleteUser(userid);
    If I change this to a singleton I could peform the Homelookup and
    create in the constructor? Any problems with concurrency?

    Ophir,
    I ran into this while testing, are you sure your started the oc4j and it is still running .. I remember some persistence issue, with the IP addr, hostname .. so I needed to clear the persistence directory in j2ee/home to have the container starting up.
    thx clemens

Maybe you are looking for

  • Bugs for Oracle XML parser

    What I first used was Oracle's xml parser (xmlparser2). I tried to read an xml file, change some nodes values, then write the file (using Transformer.transform) , all comment nodes <!-- blha blha --> were changed to <?#comment ?>. I tried to work aro

  • Using API in EBS 12.1.1

    Hi experts we have a problem with using EBS Standard packages called API, the problem is that we don't want to run or execute this package with apps user for security reason. but when we create new user and give the execute privilege on api package t

  • Can "yum" work on Enterprise Unbreakble Linux or is there another option?

    hello Yum being the package manager for ndiswrapper implies that if you use yum then ndiswrapper will install the drivers for you utilizing the system using the necessary resources. However yum didn't work for me therefore I tried to use ndiswrapper

  • Moving Library to NAS (wrinkle)

    I have an NAS and I can (using preferences> advanced) specify my itunes library as this NAS, but in iTunes, I can't see the music. I can see the music via sonos (they have a nifty "index music library" button that will rebuild after you add music.) A

  • Getting the error, "Unable to read Gateway configuration in wdbsvr.app" in error_log

    I have commented out the following lines in oracle_apache.conf. #include "E:\oracle\ora81\Apache\Apache\conf\mod__ose.conf" #include "E:\oracle\ora81\Apache\modplsql\cfg\plsql.conf" #include "E:\oracle\ora81\xdk\admin\xml.conf" include "E:\oracle\ora