Jump to content

Aggregate pattern

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by SmackBot (talk | contribs) at 08:37, 18 October 2007 (Date/fix the maintenance tags or gen fixes). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

An Aggregate pattern can refer to concepts in either statistics or computer programming. Both uses deal with considering a large case as composed of smaller, simpler, pieces.

Statistics

An aggregate pattern is an important statistical concept in many fields that rely on statistics to predict the behavior of large groups, based on the tendencies of subgroups to consistently behave in a certain way. It is particularly useful in sociology, economics, psychology, and criminology.

Computer programming

In computer programming, an aggregate pattern is a design pattern.

Members of a common subclass are each known to have certain methods. These methods return information about the state of that particular 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)

my $subtotal;
foreach my $item (@cart) {
  $subtotal += $item->query_price();
}
 
my $weight;
foreach my $item (@cart) {
  $weight += $item->query_weight();
}
 
# and so on

Aggregation uses a wrapper to encapsulate as much duplicate functionality across methods as possible:

package Cart::Basket;
 
@ISA = qw(Cart::Item);
 
sub query_price {
  my $self = shift;
  my $contents = $self->{contents};
  foreach my $item (@$contents) {
  }
}
 
# other query_ routines here...
 
sub add_item {
  my $self = shift;
  my $contents = $self->{contents};
  my $item = shift; $item->isa('Cart::Item') or die;
  push @$contents, $item;
  return 1;
}

Aggregation is like iteration in that they both present information gleaned from a number of objects through a tidy interface in one object.

See also