Hi All, How do Entity beans differ from value objects. Excluding the differences that entity beans run inside a EJB Container and the various services that the container provides to them. As far as i know the value objects are just plain and simple java objects containing set and get methods for each of their attributes and do not contain any SQL inside any of the methods which a Entity bean(BMP) may have. The similarity is that both have getter and setter methods. I need to clarify myself whether value objects can be a replacement for Entity beans. If that is not the case then, can both work in collaboration and if yes then how. What scenarios can really force one to adopt the value objects as part of the solution.
Joined: Nov 28, 2004
Isn't it that the FormBeans that are part of Struts Framework behave like value objects since, apart from being a grab bag of all the related fields inside the FormBean they also have certain validations to make sure the fields that are part of the FormBean are valid as per business rules. Also value object pattern recommends its use only when two layers need lot of data to be exchanged between them and theres a need to keep this transfer manageable. Related pieces of data can be clubbed in to a single VO and method calls can then use these VO as arguments. Am i right?
"Am i right?" - Yes, VO (or transfer objects) can improve the design of a system, and tend to be used with EJB's. A few advantages: Reduce network traffic, transfer more data in fewer remote calls (etc) - It's a J2EE dedign pattern; google will provide you with much more. Core J2EE Patterns - Transfer Object.
"two layers need lot of data to be exchanged between them" - yes, can produce cleaner code, if used in the same layer (IMHO).
Also, have a look at the Hibenate / JDO frameworks (their is forum on JavaRanch). Lastly you should know that the new EJB3 specification is going to make things a lot simpler (thankfully!).
Using VO insures Course Granied rather than Fine-Grained, with lot of advantages as discussed above. Course grained is one large object to do many things. Fine grained is spreading those responsibilities among many smaller classes.