Designing a Shopping cart


EJB design: Designing a Shopping cart

  1. Designing a Shopping cart (2 messages)

    Wish to design a shopping cart for my site. The cart should be able to add any type of item (e.g. Books, apparel, football, etc. etc.) to itself. The functionalities to be provided include Adding/Removing/Viewing/Saving.

    One school of thought says that this should be done thru a stateful ejb. but i dont want to rule out any possibility.

    Would request you to help me out on the following lines:

    1. Where to keep the cart - Web or App tier? What considerations on that?

    2. If Web, in what component specifically? JSP/JavaBean/Tag/Servlet? If App, then typically EJB. Reasons for selection of the component.

    3. How to maintain state across method invocations by user?

    Thanks in advance for your opinions.


    Threaded Messages (2)

  2. Designing a Shopping cart[ Go to top ]

    The J2EE blueprints have a decent example of a shopping cart design you can have a look at. Specifically about your questions:

    1. I prefer keeping the cart on the App server. There are a couple of reasons:
    - From a design perspective, the shopping cart is an abstraction that can be displayed on various mediums (e.g, web, client app, PDA, cellular, etc). As such, it should be independent of the particular view you are implementing (web).
    - Shopping cart operations can get relatively data intensive. For instance, you might check the stock to make sure an item can be added, sum up item prices to a total order price, etc. The app may perform and scale better if these operations are performed "near the data" (taking advantage of local app-server caches, use local interfaces for calls, ...)

    2. Some people argue that the type of component (entity/session) depends on the durabillity of your cart (i.e, session for non-persistent carts, entity for persistent ones). I prefer to allways use a session bean, because I don't like to place functionality in an entity. If the cart isn't durable, simply use stateful session beans. If it is durable, you can use an entity bean in your session bean to hold persistent data. But the actual logic should always be in a session bean. This also makes it easier to switch from one cart type to another (or even support both).

    3. That depends on the type of cart. For a durable cart, the cart is associated with the user's identity, i.e username. In this case, the cart is simply loaded according to the current logged-in username.
    If the cart isn't persistent, i.e it only lives as long as the session, you can use an HTTP session object to keep the reference to the shopping cart component. It may be a good idea to keep a reference to a local wrapper instead though... take a look at the J2EE blueprints for info.

    Hope that helps.
  3. Designing a Shopping cart[ Go to top ]

    It did help.
    could you provide me the link of the section where this is described in the blueprints?