Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Pattern for recursive variable setting over type hierarchy

Reply
Thread Tools

Pattern for recursive variable setting over type hierarchy

 
 
John McC
Guest
Posts: n/a
 
      08-20-2003
my program needs to set many variables posted from a very complex form
by working its way up a multi-tiered type hierarchy
and setting the relevant variables that apply at that level. ie:
Class A - variables aX,aY,aZ
Class B extends Class A - variables bX,bY,bZ
Class C extends Class B - variables cX,cY,cZ

at each level i recursively call the 'super' class method which
processes my request and sets the variables at that level.
this seems very longhand when i've got scores of variables to set from
my form, each 'set' method called as appropriate after validation.
is there a java pattern to handle this kind of scenario??

thanks, j
 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      08-20-2003
John McC wrote:
> my program needs to set many variables posted from a very complex form
> by working its way up a multi-tiered type hierarchy
> and setting the relevant variables that apply at that level. ie:
> Class A - variables aX,aY,aZ
> Class B extends Class A - variables bX,bY,bZ
> Class C extends Class B - variables cX,cY,cZ
>
> at each level i recursively call the 'super' class method which
> processes my request and sets the variables at that level.
> this seems very longhand when i've got scores of variables to set from
> my form, each 'set' method called as appropriate after validation.
> is there a java pattern to handle this kind of scenario??


Without seeing even pseudocode I can't guarantee it, but it sounds like
you are doing much as I would do given the data structure you describe.
Each class should take responsibility for the state it defines, and if
you then construct a subclass it should handle only the state it adds
while passing off the rest to the superclass.

Now, ideally you would do this on a request by request basis, not on a
variable by variable basis. Also, except for any universal validation
rules (and perhaps even there) it makes sense that the class wherein the
form values will be stored handles the validation rules for those values.

There is no way around taking each parameter and assigning it
individually to the appropriate field, but there may be other paradigms
for doing so that appeal to you more than what you are doing now. For
instance, if you are creating a new object to represent the form data
then you could provide a constructor at each level that accepts a Map
such as ServletRequest.getParameterMap() would provide. That Map can be
passed by each such constructor to its superclass' constructor, and each
one would pick out the parameters it wanted to use.

Now, with all that said, I would probably be looking for ways to
redesign the data structure. That would not fundamentally change the
requirements for populating it from a user request, but it might make
the actual code for doing so look more meaningful.


John Bollinger
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Harald Hein
Guest
Posts: n/a
 
      08-20-2003
"John McC" wrote:

> my program needs to set many variables posted from a very complex
> form by working its way up a multi-tiered type hierarchy


You leave that to the compiler. Use public variables or methods. Your
subclasses inherit these variables/methods and you can use them as if
you had coded them in the subclass.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two recursive calls inside of a recursive function n00m C++ 12 03-13-2008 03:18 PM
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
Visitor design pattern - breaking dependence on the target hierarchy Siphiuel C++ 0 03-07-2006 11:47 AM
tomcat 4.x : setting mime type for a directory or setting a default mime type CJ Java 1 10-29-2004 07:51 PM
XSLT : hierarchy recursive problem...help poofpoof XML 2 08-13-2004 11:31 AM



Advertisments