Aggregate pattern: Difference between revisions

Content deleted Content added
simplify
 
(4 intermediate revisions by 4 users not shown)
Line 1:
{{Short description|Concepts in statistics and computer science}}
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.
{{one source |date=March 2024}}
An '''Aggregate pattern''' can refer to concepts in either statistics or computer programming. Both uses dealsimplify withcomplexity considering a large case as composed ofinto smaller, simpler, piecesparts.
 
== Statistics ==
Line 7 ⟶ 9:
 
In ''[[Design Patterns]]'', an aggregate is not a [[Software design pattern|design pattern]] but rather refers to an object such as a list, vector, or generator which provides an interface for creating [[iterator]]s. The following example code is in [[Python (programming language)|Python]].
<sourcesyntaxhighlight lang="python">
def fibonacci(n: int):
a, b = 0, 1
Line 36 ⟶ 38:
def average(g) -> float:
return float(sum(g)) / len(g) # In Python 3 the cast to float is no longer be necessary
</syntaxhighlight>
</source>
Python hides essentially all of the details using the [https://docs.python.org/3/library/stdtypes.html#iterator-types iterator protocol]. Confusingly, ''[[Design Patterns]]'' uses "aggregate" to refer to the blank in the code <code>for x in ___:</code> which is unrelated to the term "aggregation".<ref>[[Design Patterns]], p. 22: "Aggregation implies that one object owns or is responsible for another object. ... Aggregation implies that an aggregate object and its owner have identical lifetimes."</ref> 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.
 
Line 49 ⟶ 51:
{{Reflist}}
 
{{DEFAULTSORT:Aggregate Pattern}}
[[Category:Software design patterns]]
[[Category:Articles with example Python (programming language) code]]