• 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

Any good Design Patterns for extending Value Objects?

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using one estbalished Design Pattern, the Value Object pattern, to pass data from my EJB tier to my Web tier. The issue I seem to constantly come across is that depending on the situation, I somtimes want a little extra information sent along with a partiuclar Value Object. A simplified example:

Say I have a User object. Pretty much anytme I pass a User object from the EJBs to my Web app, I want that user's:
- ID
- First Name
- Last Name
- Email address
In some situations, however, I want to pass along a special "Display Name" value that is constructed by my EJBs. In other, rare, situations I want information about the relationship between this User and another User. Maybe in another very specific circumstance, I want information about how long the user has been online.

So I could of course add these fields to my User object, and wind up with a huge Value Object that passes along a bunch of fields that are, in most cases irrelevant. But that would get messy, cumbersome to maintain, and somewhat ineffecient in terms of network data transfer.

So I am looking to see if there are any design patterns that exist for such a dilemna. For example, the Decorator pattern is sort of the approach I am looking for, except that it's designed more to alter the behavior of the object, not the interface (i.e. I couldn't use it to add a getDisplayName() method to the User object.) I've been looking through pattern catalogs, but haven't yet found anything useful.

Any thoughts?
 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe another solution would imply the usage of a DynaBeans.

--
:alex |.::the_mindstorm::.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does the client side know which methods the objects will have? Does it already know from context, or will it need to probe the VO?
 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DynaBeans... we're not using Struts (I'm not sure if DynaBeans would work here even if we were) but maybe I will check out the general structure to see if it would work.

Ideally, I would want the client to know the VO's interface and not have to probe. Especially with the other programmers I'm working with , I'm really into type-safety these days.
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dave taubler:
DynaBeans... we're not using Struts (I'm not sure if DynaBeans would work here even if we were) but maybe I will check out the general structure to see if it would work.

Ideally, I would want the client to know the VO's interface and not have to probe. Especially with the other programmers I'm working with , I'm really into type-safety these days.



DynaBeans are not Struts-specific. They are supported in Commons BeanUtils, too.
 
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should use composition. Create a new value object type that includes a copy of a UserVO along with the additional information.

Example:



Note both UserVO and DisplayUserVO are immutable and cannot be extended. This pattern is preferable to subclassing in most situations.

Best regards
Geoffrey
[ March 14, 2005: Message edited by: Geoffrey Falk ]
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic