fine grained vs. coarse grained EJBs


EJB design: fine grained vs. coarse grained EJBs

  1. fine grained vs. coarse grained EJBs (2 messages)

    can anybody explain the above conceptions. i am not quite clear about that. any resources on the Internet is also ok.

  2. The simple explanation is that in fine grained EJB's,
    every object will be made a separate EJB. With coarse grained EJB's, you wil have big "fat" EJB,s, containing a lot of application logic.

    An example: You want to represent an order consting of a number of order lines.
    You can make each order line its own EJB (fine grained), or
    you can have one EJB encompassing the entire order (coarse grained). Of course, in the coarse grained case, the order EJB can still use other helper classes for the actual implementation, but they are not exposed to the client.

    There are pro's and con's to each approach - in general, coarse grained EJB's seem to be preferred.

    Coarse grained:
    + Fewer EJB calls - less network load, fewer transaction context,
    + Simpler deployment
    + Fewer objects for the application programmer to learn
    - CMP harder to set up
    - Potentially less reuse
    - Less distribution

       Niels Harremo√ęs

  3. Also, keep in mind that EJBs should only be created for data that must be remotely accessed. If it is only used on the server-side, there are other mechanism available with much less overhead.

    For more information and guidelines on this issue, see the J2EE Blueprints.