Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Value objects

 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vivek Viswanathan
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Saran Vel
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Vivek Viswanathan
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sandy gupta
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek,
WL 6.0 Beta 2 supports the ejb 2.0 spec and all u have to do is include a new jar called ejb20.jar in the classpath.
Sahil
 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the feedback. It cleared up many doubts.
 
Vivek Viswanathan
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx
I have to try out WL 6.0 beta
Is the final release of WL 6.0 avaliable for Linux -- any ideas on that ???
vivek
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic