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

Similar Messages

  • 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.

  • 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.

  • 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?

  • 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/]

  • 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.

  • Session Facade and Business Delegate Pattern

    Hi!
    The only way to use the Session Facade Pattern, is if I use EJB for Persistence.
    Is valid to do this?:
    I use Ejb for simple update, insert querys. From my business delegate I call the Session Facade Layer, and from this I invoque Entyties for persistence.
    But if I have complex querys, is correct to make PL SQL Procedures and do the following:
    From my business delegate I call to the Dao layer, and from this via JDBC I call the Procedure.
    Please explain me the best form to do this, having complex querys for reporting and simple querys for inserts/update.
    Is valid to combine the use of CMP (for simple persistence cases), BMP (for complex persistence cases), and JDBC for complex select querys with multiple result rows.
    Thanks!!

    The session facade is borrowed from the facade pattern, so you could have a facade to almost anything.
    A session facade is usually against other beans...for example if you
    (Not deployed as CMR)
    1. Address bean
    2. Phone Bean
    3. Customer bean
    as entity beans then you can build a session facade such as
    CustomerFacadeBean which will CreateReadUpdateDelete(CRUD) address and phone as well when a customer is CRUD ed.
    In your case you said you have very complex sql's so one way would be
    Business Delegate -> Session Facade -> (Bean Managed) Entity Bean -> DataAccessObject.
    If you think this is a overkill then, write a custom pattern such as DataDelegate
    DataDelegate -> (Bean Managed) Entity Bean -> DataAccessObject.
    In the above scenario you should be quite sure that the system will not evolve into a case mentioned above such as when customer is deleted a phone and address object are also thrown away.
    You said this scenario
    Business Delegate -> DAO..
    I don't think this is a good idea because, a business delegate is a proxy against business objects....and usualy in J2EE business objects are session beans. Entity and DAO objects are data objects not business ones.
    Besides if you do the above scenario you will end up wiring all the transactions, etc etc in your DAO which is not a good idea.
    Although you could use BusinesDelegates against entity beans it will lead to a misnomer.

  • BUSINESS  DELEGATE PATTERN AND DAO

    Culd anyone explain me then with an example?
    Thanks in advance.

    SubjectDelegate subjectDelegate = new SubjectDelegate();
    //This is an example which shows that the form values are set in to a transfer object
    //and then through the delegate it calls the createSubject() method from ejb's
    // subjectVO.setSubjectName(createSubjectPMTLForm.getSubjectName());
    // subjectVO.set ........so on....
    subjectDelegate.createSubject(subjectVO);
    # This will call the method in the delegate(SubjectDelegate)...which will further delegate it to the next level.
    public void createSubject(SubjectVO subjectVO)throws Exception {
         try {
              getFacadeInstance();
              subjectFacade.createSubject(subjectVO);
         } catch (Exception e) { }
    # here facade is the stateless session bean which can be used to call entity bean to crete the record in database or a DAO
    I hope i did not confuse u much.........
    Some client----------> Delegate-------->Facade(Session bean)--------->EntityBean or DAO
    Reply with ur mail ID if u still did not understand how to use the delegate.
    Regards,
    Aru

  • 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.

  • 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.

  • === 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 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 Session Facade and Business Delegate??

    Hello,
    I am currently working on design patterns and I am confused what the difference is between the Session Facade and Business Delegate pattern. They look identical.
    What's the difference?
    Balteo.

    We implement Business Delegators (BD) as follows:
    1. The client always talks to the BD.
    2. The BD then talks to either our Session Facade, Session EJB, or Java Class, etc, etc directly.
    This allows the client end code to never change whilst allowing our BD to swap between different providers of the service we require.
    It's the good 'ole "layer of indirection" thingy.

Maybe you are looking for