by
allistar >> Sat, 9 Oct 2004 7:34:31 GMT
A better way would be to have a root object (let's call it "BoxOfficeRoot" for now) and have only one instance of this. On this class you would define a collection called "allBoxOfficeSales" of type "BoxOfficeDict" (it would be better to use a dictionary as removing objects from arrays can be very slow. Also with a dictionary it would be keyed by something (like "date" for instance) so doing a query on it would be able to be optimised).
The MovieSale class would have an reference called "myBoxOfficeRoot" which would be inversed to "allBoxOfficeSales". This way you have database integrety (without an inverse if you deleted one of the MovieSale objects the collection would be left with a "hole" in it, which isn't good).
When you create a movie sale it would make sense to have some sort of "set" method that would take the details of the sale, such as:
date: Date; amount: Decimal etc.
If you want to see a total of all sales in the database, instead of summing them in a loop you could always sum them as the sale is added. Do this by adding a property called "totalMovieSalesValue" and in th "set" method on MovieSale you would do something like:
app.myBoxOfficeRoot.totalMovieSales := app.myBoxOfficeRoot.totalMovieSales + amount;
(although it would be better to put a "updateTotalMovieSales" method on BoxOfficeRoot).
you'll also need to make sure that when you delete a MovieSale then you reduce this total. Doing it this way means that you always have a running total and you don't need to accumulate it each time you want it.
Using ".firstInstance()" in production code is never a good idea, it pays to have a root object and hang things off that. Then you just need to go "app.myBoxOfficeRoot" to get the BoxOfficeRoot object. In the application initialise you'll need a "myBoxOfficeRoot := BoxOfficeRoot.firstInstance()" (which breaks my previous "rule", but in this case it is necessary).
(Also in your code you posted you could have achieved the whole things with this one line:
write "SALES ARRAY SIZE: " & BoxOfficeArray.firstInstance().size().String;
)
I hope this helps,
Allistar.
--
------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst
allistar@silvermoon.co.nz
Auckland, NEW ZEALAND
Silvermoon Software
Specialising in JADE development and consulting
Visit us at:
http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at:
www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------