Reference articles on history, science, culture and more
Encyclopedia

Aggregate pattern

Concepts in statistics and computer science

An Aggregate pattern can refer to concepts in either statistics or computer programming. Both uses simplify complexity into smaller, simpler parts.

01Statistics

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.

02Computer 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: int): 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: int) -> int: total = 0 for x in fibonacci(n): total += x return total def fibsum_alt(n: int) -> int: """ 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) -> float: return float(sum(g)) / len(g) # In Python 3 the cast to float is 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.

Watch videos about Aggregate patternExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article Aggregate pattern, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.