Aggregate pattern: Difference between revisions

Content deleted Content added
m stub sort
Minor change
Line 13:
Members of a common [[Subclass (computer science)|subclass]] are each known to have certain [[Method (computer science)|method]]s. These methods return information about the state of that particular [[object (computer science)|object]]. It does happen that an application is concerned with an aggregation, or amalgamation, of data from several object of the same type. This leads to code being repeated around the program:
 
(Perl example)
<source lang="perl">
my $subtotal;
foreach my $item (@cart) {
$subtotal += $item->query_price();
}
my $weight;
foreach my $item (@cart) {
$weight += $item->query_weight();
}
# and so on
</source>