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?