# Aggregate pattern

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 Design Patterns, an aggregate is not a design pattern but rather refers to an object such as a list, vector, or generator which provides an interface for creating iterators. The following example code is in Python.

```def fibonacci(n):
a,b = 0,1
count = 0
while count < n:
count += 1
a,b = b, a+b
yield a

for x in fibonacci(10):
print x

def fibsum(n):
total = 0
for x in fibonacci(n):
total += x

def fibsum_alt(n):
"""
Alternate implementation. demonstration that Python's built-in function sum()
works with arbitrary iterators.
"""
return sum(fibonacci(n))

myNumbers = [1,7,4,3,22]

def average(g):
return float(sum(g))/len(g) # In Python 3 the cast to float will no longer be necessary
```

Python hides essentially all of the details using the iterator protocol. Confusingly, Design Patterns uses "aggregate" to refer to the blank in the code `for x in ___:` which is unrelated to the term "aggregation". Neither of these terms refer to the statistical aggregation of data such as the act of adding up the Fibonacci sequence or taking the average of a list of numbers.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8904346,"math_prob":0.8960747,"size":2019,"snap":"2019-26-2019-30","text_gpt3_token_len":447,"char_repetition_ratio":0.10223325,"word_repetition_ratio":0.044585988,"special_character_ratio":0.22634968,"punctuation_ratio":0.12827225,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9961901,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-21T07:34:35Z\",\"WARC-Record-ID\":\"<urn:uuid:6b7cce8e-cba4-459c-9965-89acee8dfa7c>\",\"Content-Length\":\"34883\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:01947541-a4ae-48e2-81b8-31610ce793a1>\",\"WARC-Concurrent-To\":\"<urn:uuid:854ae3d3-e02d-45f0-ae91-e273831d9a13>\",\"WARC-IP-Address\":\"208.80.154.224\",\"WARC-Target-URI\":\"https://en.wikipedia.org/wiki/Aggregate_pattern\",\"WARC-Payload-Digest\":\"sha1:3O7HUJUPBUX6JZDNZE3PGTPGVPETESYN\",\"WARC-Block-Digest\":\"sha1:JCA225ZMER2WTO4NKRAB5MDSUWZPEDMR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195526931.25_warc_CC-MAIN-20190721061720-20190721083720-00280.warc.gz\"}"}