How does EJB support polymorphism?
Posted in EJB Interview Questions, HR Interview Questions Because an EJB consists of multiple “parts”, inheritance is achievable in a rather limited fashion (see FAQ answer on inheritance here). There have been noteworthy suggestions on using multiple inheritance of the remote interface to achieve polymorphism, but the problem of how to share method signatures across whole EJBs remains to be addressed. The following is one solution to achieving polymorphism with Session Beans. It has been tried and tested on Web Logic Apps Server 4.50 with no problems so far. We will use an example to show how it’s done. Say, there are 2 session beans, Tiger and Lion that share some method signatures but provide different implementations of the methods. • Animal Home and Animal are the home and remote interfaces. The signatures of the polymorphic methods are in Animal. • Animal Bean is the base implementation bean. • Tiger Bean and Lion Bean extend from Animal Bean.
Because an EJB consists of multiple “parts”, inheritance is achievable in a rather limited fashion (see FAQ answer on inheritance here). There have been noteworthy suggestions on using multiple inheritance of the remote interface to achieve polymorphism, but the problem of how to share method signatures across whole EJBs remains to be addressed. The following is one solution to achieving polymorphism with Session Beans. It has been tried and tested on WebLogic Apps Server 4.50 with no problems so far. We will use an example to show how it’s done. Say, there are 2 session beans, Tiger and Lion, that share some method signatures but provide different implementations of the methods. · AnimalHome and Animal are the home and remote interfaces. The signatures of the polymorphic methods are in Animal. · AnimalBean is the base implementation bean. · TigerBean and LionBean extend from AnimalBean. They may override the methods of AnimalBean, implementing different behaviors.