Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design Question

 
HungryJavaGoat
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a Value object (Transfer object pattern) and persistance object have "USING" relationship ?

That is ValueObject's overloaded constructor will take persistance object as parameter and get the details of persistance object and set the details to its member variables.

My question here is , is it a correct design ? or shoud i use any static method in ValueObject to give a instance of valueobject with the details or an external method (out of value object ) which will create a value object with details from persistance object.

Thanks in Advance
 
Amit M Tank
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I were to design an application with Value Objects and Persistence Objects in an EJB environment which uses component based architecture, then I would not have such kind of Constructor in my ValueObject.

If you have such constructor or method in the value object (persistence object as a parameter) then you are coupling your value object to the persistence object. I would infact have my value object (serializable) and have it populated using a Utility class(with static methods) on the server side which can populate value object from the persistence object and vice versa.

So this value object can be used in your web layer as well as EJB layer without having the class definition to be dependant on the Persistence Class def.
 
kiran mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be easy to add a constructor to the persistence object, which would have the value object as input and to have a method getValueObject() which would return the value object.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic