EJB design: Adapter in J2EE

  1. Adapter in J2EE (4 messages)

    I have large number of Entity beans(CMP) and session beans. I was thinking to apply Adapter pattern(have a class with blank implementation of interface methods and use it as super class for all other classes) while implementing these beans. But I googled to find if it was normal pratice to do so. But I could not found any relevant information. The patterns available for J2EE, also dont discuss much about adapter pattern. I was just wondering, what could be implecations for using adapter pattern in this way in J2EE application ? Please provide your views.

    Threaded Messages (4)

  2. Re: Adapter in J2EE[ Go to top ]

    No it is not a normal practice. Use adapter when you need to have two system communicate.
  3. Business interface pattern[ Go to top ]

    Why do u want to have a common interface between Session and Entity beans? Both types of beans are for entirely different purposes . A common pattern though used in EJBS similar to ur lines is the business interface pattern. But this is used as a super interface with business methods being implemented by the underlying entity beans. This helps in switching between BMPs and CMPs. Thanks
  4. Re: Adapter in J2EE[ Go to top ]

    Ravish, you seem to have mixed the patterns for entity and session beans. The Adapter pattern is commonly used in session beans. For e.g. you have an EJB components in different applications interacting with each other. Web Application -> EJB comp. 1 - Adapter - EJB comp 2. Where EJB 1 and 2 are both session beans not Entity beans at all. Entity beans have a completely different purpose. DAO may be used to interface between your session beans and Entity beans (I usually have a helper or utility class working between the Session and Entity beans.) Let me know if you need more help. -Vinant Pandey
  5. Re: Adapter in J2EE[ Go to top ]

    I can understand your point but solution that you thought about is not quite rite.(Sorry for this comment). Session Bean:- For Session bean you want to have a proxy object which will act as a Remote proxy. http://en.wikipedia.org/wiki/Proxy_pattern I hope these proxy classes will make your life very easy and code would be quite cleaner since all the lookup and casting operations are hidden inside proxy object. Entity Bean:- Even here you need something like proxy, but not proxy since it bridges the operations while entity represnets a unit of data. This is what you can do... 1. Deisign a EntityFinder which will take care of look up and finding the entity bean from client request(i.e PK etc). 2. Encapsulate this bean into a light weight POJO which is backed up by this entity bean instance. This pojo takes the ineterface of entity bean and performs all the operations interanally. I can tell you for sure that my soution for Session bean is a best way to handle sessions beans. But I myself dont feel so upbeat about the entity bean solution. But if you have understood the underlying concept you can try sme variations to suit your requirement. HOpe this helps shrini