Discussions

EJB design: EJB Inheritance...

  1. EJB Inheritance... (2 messages)

    I was reading throught the EJB 2.0 specification, and found the following in the Apendix D: Frequently Asked Question under the "Inheritance" section:

    "[...]the Bean Provider can take advantage of the Java language support for inheritance as follows:
    * Interface inheritance. It is possible to use the Java language interface inheritance mechanism for inheritance of the home and component interfaces. A component may derive its home and component interfaces from some "parent" home and component interfaces; the component then can be used anywhere where a component with the parent interfaces is expected. This is a Java language feature, and its use is transparent to the EJB Container.

    * Implementation class inheritance. It is possible to take advantage of the Java class implementation inheritance mechanism for the enterprise bean class. For example, the class CheckingAccountBean class can extend the AccountBean class to inherit the implementation of the business methods.

    This baffled me, because one of the stronges points against Entity EJB is the lack of Inheritance support... So I checked the EJB 1.1, and found the same text on the Appendix B...

    Now I'm puzzled... This means that Inheritance is supported by EJB spec (class inheritance, not component inheritance) but not supported by containers (thus violating the spec), all of us who think that inheritance is not supported were wrong, or there is something I'm missing?

    Rafael

    Threaded Messages (2)

  2. EJB Inheritance...[ Go to top ]

    Hi Rafael,

    in this article everything is explained:
    http://www.theserverside.com//resources/article.jsp?l=EJBInheritance

    Reto
  3. EJB Inheritance...[ Go to top ]

    I personally don't like the data-model inheritance idiom suggested in this article. I don't see a lot of practical good that it does other than implementing "polymorphic" finders. You can get the same result by simply using home methods instead of finders.

    Anyway, the point about inheritance in EJB is that EJB does support normal Java inheritance. What it doesn't support is "component inheritance", a concept which has no widely accepted meaning. Everything you could do with your regular Java objects with regard to inheritance still applies to EJB (except for some really minor issues concerning CORBA portability, etc).
    Java inheritance is supported by all compliant containers. Every Java class extends something. If you don't define a base-class yourself, your class extends Object. You can define a different base class if you want. There is no reason why that should bother the container. Particularly, you can also extend the implementation class of another bean.

    Gal