You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vladimir Levin <ap...@hotmail.com> on 2002/03/12 03:58:22 UTC

Development approach question

Hi, I have a basic design-level question to ask of those who are
using the struts framework. The question concerns how data from
the database get retrieved into the 'web-tier' beans
of the application when table joins are involved.

One approach is to nest objects. e.g. say we want to display
all the BANANA records belonging to each MONKEY in our database.

we can create a Monkey object and assign a list of Banana objects
to each Monkey.

public class Monkey {
  private String name;
  private List bananas; //type of objects in list is Banana

  public String getName() { return name; }
  public void setName(String name) { this.name = name; }
  public List getBananas() { return bananas; }
  public void setBananas(List bananas) { this.bananas = bananas; }
}

public class Banana {
  private String id;
  public String getId() { return id; }
  public void setId(String id) { this.id = id; }
}

This approach implies using the nested taglibs package. It has
potential downside that many objects get created.

Another approach is to create a 'super' object to aggregate the
data for the join between tables. e.g.

public class MonkeyBanana {
  private String name; //Monkey name
  private String id; //Banana id;
}

This is essentially a denormalization of the Monkey and Banana
objects. It is more redundant, but we don't need to use the
nested taglib package and we create fewer objects.

Does anyone have advice regarding which approach is better?

Vlad






_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Development approach question

Posted by Arron Bates <ar...@pacific.net.au>.
If known for nothing else, I may go down for creating the infamous 
Monkey/Banana bean model example :)

I don't think that one object per row is much of an overhead for the 
benefit it brings. You are going to have to marshal your results anyway, 
so you may as well create separate objects. Hell, you could even have 
the beans as a proxy only and go driect through to the result set. But 
that's not very MVC.

The nested tags don't "imply" anything. They simply make easier work of 
some more complex markup. Even with nested beans you can use the old 
tags. The nested tags are also better at adaptation. If your spec 
changes, then it will be easier to update with the nested system. Even 
if I'm not nesting beans, I still use the nested tags. They simply make 
life easier.

You could take me as being bias :) ... so are there any other opinions 
out there?...

Arron.

Vladimir Levin wrote:

> Hi, I have a basic design-level question to ask of those who are
> using the struts framework. The question concerns how data from
> the database get retrieved into the 'web-tier' beans
> of the application when table joins are involved.
>
> One approach is to nest objects. e.g. say we want to display
> all the BANANA records belonging to each MONKEY in our database.
>
> we can create a Monkey object and assign a list of Banana objects
> to each Monkey.
>
> public class Monkey {
>  private String name;
>  private List bananas; //type of objects in list is Banana
>
>  public String getName() { return name; }
>  public void setName(String name) { this.name = name; }
>  public List getBananas() { return bananas; }
>  public void setBananas(List bananas) { this.bananas = bananas; }
> }
>
> public class Banana {
>  private String id;
>  public String getId() { return id; }
>  public void setId(String id) { this.id = id; }
> }
>
> This approach implies using the nested taglibs package. It has
> potential downside that many objects get created.
>
> Another approach is to create a 'super' object to aggregate the
> data for the join between tables. e.g.
>
> public class MonkeyBanana {
>  private String name; //Monkey name
>  private String id; //Banana id;
> }
>
> This is essentially a denormalization of the Monkey and Banana
> objects. It is more redundant, but we don't need to use the
> nested taglib package and we create fewer objects.
>
> Does anyone have advice regarding which approach is better?
>
> Vlad
>
>
>
>
>
>
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
>
>
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Development approach question

Posted by keithBacon <ke...@yahoo.com>.
Hi Vlad,
What ever results in the least/simplest/fastest code!
The way I look at is that you have a special 'ViewSupport' layer in your app
that provides sorted copies of the data for presentation. This is seperate from
the main business logic. You can supply the data as maps/sets/lists normalised
or not. The 'rules' of MVC are a bit irrelevant here. You are more concerned
with performance & simplicity. The data here is 'snap-shot' copies of the data,
not really the main data model & isn't updated. The formats of data returned
are deterrmined by the requirements of the view.
I'm speaking here of database/business systems other types may be very
different.
Keith.


--- Vladimir Levin <ap...@hotmail.com> wrote:
> Hi, I have a basic design-level question to ask of those who are
> using the struts framework. The question concerns how data from
> the database get retrieved into the 'web-tier' beans
> of the application when table joins are involved.
> 
> One approach is to nest objects. e.g. say we want to display
> all the BANANA records belonging to each MONKEY in our database.
> 
> we can create a Monkey object and assign a list of Banana objects
> to each Monkey.
> 
> public class Monkey {
>   private String name;
>   private List bananas; //type of objects in list is Banana
> 
>   public String getName() { return name; }
>   public void setName(String name) { this.name = name; }
>   public List getBananas() { return bananas; }
>   public void setBananas(List bananas) { this.bananas = bananas; }
> }
> 
> public class Banana {
>   private String id;
>   public String getId() { return id; }
>   public void setId(String id) { this.id = id; }
> }
> 
> This approach implies using the nested taglibs package. It has
> potential downside that many objects get created.
> 
> Another approach is to create a 'super' object to aggregate the
> data for the join between tables. e.g.
> 
> public class MonkeyBanana {
>   private String name; //Monkey name
>   private String id; //Banana id;
> }
> 
> This is essentially a denormalization of the Monkey and Banana
> objects. It is more redundant, but we don't need to use the
> nested taglib package and we create fewer objects.
> 
> Does anyone have advice regarding which approach is better?
> 
> Vlad
> 
> 
> 
> 
> 
> 
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Search the archive:-
http://www.mail-archive.com/struts-user%40jakarta.apache.org/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Bacon - Looking for struts work - South-East UK.
phone UK 07960 011275

__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>