• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Value Objects on JwebPlus

 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Paul,
The JWeb+ Trial has a question about Value Objects. One of the correct answers is "It's a good idea that the Value Object be immutable" However, in Sun's discussion of the Value Objects they states "It is a design choice as to whether the ValueObject attributes are private and access through getters and setters or all the attributes are public" This doesn't sound like it immutable to me. Did I miss something?
 
Enthuware Software Support
Posts: 4803
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to search object ValueObject pattern on google. You'll find a lot of good articles explaining this. However, the basic idea is this:
Value Objects are basically used to transport multiple values at one go between the client and the server. The point is that making such objects mutable gives the client a false sense of manipulating the data. Value Object is just a local object, when you call a setter on a ValueObject, it does not mean anything on the server side. It's just the local object that you are modifying.
Value Objects are almost always read only and this should also reflect through it's implementation by making it immutable.
HTH,
Paul.

------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed in that implementation it would make sense. If you read Sun's there is a part of the document where they discuss if you have a large number of Attributes to configure in an EJB Entity, you can use a ValueObject do the Setting there and in the EJB, simply expose a method such as setPara(ValueObject)
My point is, it is not a design requirement of the ValueObject Pattern that the ValueObject be immutable. I agree you may have some design considerations where making it so would be beneficial but, there are others where it would not.
 
Paul Anilprem
Enthuware Software Support
Posts: 4803
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course, it is not a design requirement but it is a prefered way. Having getters and setters + private fields instead of no getters/setters + public fields is also not a design "requirement", but we almost always go for the former. Why? It is a cleaner and better "object oriented" way.
------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD
 
Paul Anilprem
Enthuware Software Support
Posts: 4803
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What sun is talking about is a different thing. Using something like setPara(ValueObject) does not mean that the value object has to be mutable. You can create a new valueobject and pass it in.
------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 5 (If you print out the Printable version) it discusses
"Upadateable Value Objects Strategy
This Strategy is also known as the Mutable Value Objects strategy ..."
 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Carl,
First of all Congrats on the exam success!!!
Secondly, I've just been going through the pattern docs on Sun and in a little sectiobn at the beginning they state that the <b>patterns</b> are global abstract solutions that can be coded many ways and that <b>strategies</b> are coding solutions that have come up in many projects so they are providing info on them as useful structures and waiting to see if they can create a new pattern from those strategies at a later date.
It's all in the semantics
Bye,

------------------
Terry Doyle
Sun Certified Programmer for Java 2 Platform
 
reply
    Bookmark Topic Watch Topic
  • New Topic