Hello Folks, Why do we need Home and Remote Interface in EJBs?Why can't we keep both business methods and life-cycle methods in any one interface instead of two interfaces...any specific reason.Please help me out. Regards, Ravi
Just beginning to wrap my arms around EJB, but, for the purposes of stretching my brain and contrasting my answer with other folks, thoughts include: * Home vs. Object interfaces give the container more flexibility in how it implements getting remote clients to instances of business logic/data. More flexibility lets containers optimize in various ways, re: caching, loading, etc. * Once the remote client has a handle to the EJBObject stub, it may no longer need the EJBHome interface object, and so can let that object go to be garbage-collected. * Just general, good, class/interface design where the interface doesn't attempt to accomplish two fundamentally separate kinds of things (lifecycle management vs. business methods).
You can think of the Home interface as really being a factory for creating/locating your actual EJBObjects. In general it's a good design to separate your business object interface (Remote interface) from the interface that manages the location/life-cycle of your business objects. You should not mingle up the two.