The Session Bean Code

The session bean declared for the shopping cart EJB demonstrates object-oriented code reuse by simply extending the ShoppingCartBean class developed for the first example. Since the EJB specification allows EJBs to be part of an inheritance hierarchy (even though they themselves cannot be extended), this use of inheritance is allowed.

The ejbCreate method shown next has been overloaded to accept an argument for the userID. This integer value is passed to the method and used to set the userID for the shopping cart. All other functionality provided by the session bean is in fact provided by its superclass, the ShoppingCartBean. Note that any methods exposed in the session bean's remote interface must be declared public (which ...

Get J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.