• 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

Doubt in UML distilled by Martin Fowler page 94

 
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 94 of UML Distilled, the author says that value objects can sometimes be shared among many objects. But what I understand about value objects and reference objects is that value objects are never shared and every object using a value object has a separate distinct copy of the value object . But if an object is a reference object, there is only one object and all the objects using that reference object have their own references to that reference object. Hence my understanding is value objects cannot be shared and reference objects are always shared by their definition. Hence I do not understand the author's statement that value objects can sometimes be shared.

Can someone please clarify?
 
author
Posts: 608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

On page 94 of UML Distilled, the author says that value objects can sometimes be shared among many objects. But what I understand about value objects and reference objects is that value objects are never shared and every object using a value object has a separate distinct copy of the value object . But if an object is a reference object, there is only one object and all the objects using that reference object have their own references to that reference object. Hence my understanding is value objects cannot be shared and reference objects are always shared by their definition. Hence I do not understand the author's statement that value objects can sometimes be shared.



You can do whatever you want with a value object. For example, a JSP might use it to populate a page and then a servelet use it to create an entity bean perhaps. You don't need distinct copies to do this, although there's nothing stoping you from doing so.

- Scott
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what Fowler wanted to get at is that value objects often are also immutable, and therefore it's safe to reuse them.
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how would you reuse a value object? You would have one value object and several references to the same object right? If you do that, aren't you treating it like a reference object? In this case, what is the difference between a value object and reference object?
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by B Sathish:
But how would you reuse a value object? You would have one value object and several references to the same object right? If you do that, aren't you treating it like a reference object? In this case, what is the difference between a value object and reference object?



With a value object, *it doesn't matter* whether you reuse the same object, or create a new one with the same value. The client code shouldn't even notice.
 
reply
    Bookmark Topic Watch Topic
  • New Topic