> -----Original Message----- > From: Fran Fabrizio [mailto:[EMAIL PROTECTED]] > Sent: 13 June 2002 13:23 > To: Jeff AA > Cc: [EMAIL PROTECTED] > Subject: RE: separating C from V in MVC > > > >Controller: > >----------- > >my $Stale = Model::WatchCollection->new( status => 'stale' ); > > > >Controller: > >----------- > >my $WC = Model::WatchCollection->new(); > > Out of these two, I would think that the first one is actually > better. What if you have 300,000 watches and only 25 are stale, for > example (numbers that are not all that far from the truth, in my
Don't make the mistake of fetching all the data when a Collection is instantiated. It is usually better to make the Collection only really fetch data when a View actually asks for it by calling $WC->fetch( status => 'stale' ), after all, sometimes you might go down another route and the View might never call fetch() - for example if there is an exception and you decide not to bother showing stale Watches. Also, you should generally not fetch everything from the database unless there is a very good reason to do so. Try to keep your memory usage to a minimum, and restrict the result set to something useful. I recall a system that used to pop up a dialog saying 'Warning: This will return 645,345 rows' and the only user option was 'Ok'! I have seen about 4.2 million Collection designs, and my current favourite is an abstraction of the Borland Data Engine DB/Table/Dataset design (BDE) in conjunction with some of the Java collection concepts. Common Collection niceties include things like 'find me Watch ABC' in the Collection. A Collection can have the concept of a 'current' thing so that a View can display both the list of Watches in a table, and more detailed attributes of the 'currently selected' Watch object etc. If you are going to support paginated collections, you should build this into your base Collection class. So far we have been talking about flat Collections, don't forget that some of them are not flat, but hierarchical - e.g. tree-like, and some are circular e.g. no beginning and no end, etc. ciao Jeff