Hi, From what I understand, value objects are a convenient way of reflecting database table columns, which can be used in entity beans. They have private variables which correspond to the columns in the database table,with accessor and mutator method for getting and setting these values. The reason for making the data private is for data hiding, right ? What if we have all the variables in the value objects as public, and not have accessor and mutator methods for them ? Will this be a desin flaw, or will it pose new problems on the long run in an application ? Any response will be very helpful. Thanks.
hi Yes you are right, the basic reason for making variables private is for data hiding, and by making them public, you are in a way violating the basic concept of data hiding that Objects provide you. This statement is particularly debate able since all that you are creating is Value Objects that do on contain any processing but just act as a Storage area for transferring data from one tier to another. I have almost the similar problem in the project that I am working on, we are using Value Objects as the super class to the Entiy Bean class, since we are using Container Managed Persistence all the attributes of the Value Object have to declared as public. The reason for this inheritance is to increase code reuse and reduction in code duplication that results in creating two classes that contain exactly the same fields. I feel that since I am extending Entity Beans from Value Object and the Entity Bean (with Container Manager Persistence) requires that all the database field variables be declared as public, it is all right to use this pattern even though it does not stick the OO Concept of Data encapsulation. I hope I was helpful :-) Vivek Viswanathan
Hi Vivek, In the case u have mentioned, what abt using ejb2.0, such that the value object can have private variables ? In this case i can use abstract get and set methods of the entitybean to set values in the EJB,and by passing the value object between client and EJB. What r the pros and cons of this design?
Sun Certified Java2 Programmer
Joined: Mar 03, 2001
Hi I still have to go through EJB2.0 Spec, I have not read it. Do any Appservers support EJB2.0 ? I am using Weblogic 5.1