wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Value Objects on JwebPlus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Value Objects on JwebPlus" Watch "Value Objects on JwebPlus" New topic
Author

Value Objects on JwebPlus

Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
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?


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
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


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
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
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
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
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
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

Joined: Jun 13, 2000
Posts: 3340
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 ..."
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
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


Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
 
Don't get me started about those stupid light bulbs.
 
subject: Value Objects on JwebPlus
 
Similar Threads
Value Object(VO) - Immutable class
Doubt in UML distilled by Martin Fowler page 94
why wrapper simple object making not working?
Final object's value could be changed?
Wrapper Classes