Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on Value Objects

 
chandru ram
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw an application that is using the following design for ValueObjects:
public class RequestVO {
public void setName() {}

...... similarly other methods.

}
public class ResponseVO extends RequestVO {
}

Like this the response extends the request VO. Is there any advantage of using such a design.I need some comments on this.
Thanks in advance,
chandru ram
 
Tiberiu Paun
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you posted this at EJB forum, then I won't tell u about inheritance.
U may wish to do this kind of design when u want to return something from an ejb server, but u may don't know what u will return.
For example, lets say that u have your response from server as an array of classes requestvo (u have no ideea how big the array is, so u have to use array).
in these requestvo classes, some of them might have something different one from the other (lets say u do a select, and according to a customer_type, u make a difference in the result, for example the class requestvo should have additional fields in it, but there is no point of putting those fields in it, while not all the classes in the response should have it , even could have nothing in common but the only field inherited from mother class).
To be more specific: u want to return in an array customer's address, customer's children, etc, and, according to customer type (government, corporation, etc), u may wish to add additional_inform class if customer_type=corporation, which is different from the one of a government.
The only easy way is to do this design:
response would be : requestvo[]
class address extends requestvo
class additional_inform_corporate extends requestvo //information about category of corporation, how many employess, etc
class additional_inform_private extends requestvo //information about how many children, his address, marital status
In this way, the input parameter of the method would be the customer_id, no matter what type of customer it is, while u would have to do a retrieve, to see the customer type, which would not be desirable. Then u could see with "instanceof", or getClass(), what type of class that is, and invoke the proper methods on it.
In other "beautiful minds" (I've seen it at Amdocs), the return type of a method is Response and ResponseException (why did they need J2EE for, cause this looks something like CORBA?).
Hope I didn't misslead u in any way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!