I've been thinking about the difference in arguments of business methods for local and remote components as described in Headfirst EJB. If the component is local then what is passed as the business method arg is a copy of the reference to the object on the same heap, if it's remote it's a copy of the object from the clients heap to the server's heap.
I know that this relates to business logic, normal Java rules etc rather than being EJB specific, but can anybody think of a scenario where the internal coding of a business method would be different for both cases. It would help reinforce the idea.
One major difference is that when an object is passed as an argument to EJB's method and EJB's method does some action on that object and after the method returns the client works further on that object. 1. In case of Remote component, we need to explicitly return the object. 2. In case of Local component, we might not want to return anything as we are already working on the same object.
I always perfer to use remote components rather than local components. One reason is that in most of the application servers you can make the method invocations on remote components to "pass by reference" instead of "pass by value" by just checking a checkbox. The benefit of keeping remote components always is that in future if you want to move your EJBs on different machine, you don't need to make changes to the code.
Harpreet - I like your above example. One solution to the problem suggested by HeadFirst EJB is to maintain consistency have all arguments a copy of an object. You can do this with local interfaces by cloning the object and then passing a reference to the cloned object as a method argument.