Aggregate Pattern - Computer Programming

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.

mylist = for item in mylist: print "Mom, we're out of " + item + "!" 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 return total def fibsum_alt(n): """ Alternate implementation. demonstration that Python's built-in function sum works with arbitrary iterators """ return sum(fibonacci(n)) myNumbers = def average(g): return float(sum(g))/len(g) #in Python 3.0 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.

Read more about this topic:  Aggregate Pattern

Famous quotes containing the words computer and/or programming:

    What, then, is the basic difference between today’s computer and an intelligent being? It is that the computer can be made to see but not to perceive. What matters here is not that the computer is without consciousness but that thus far it is incapable of the spontaneous grasp of pattern—a capacity essential to perception and intelligence.
    Rudolf Arnheim (b. 1904)

    If there is a price to pay for the privilege of spending the early years of child rearing in the driver’s seat, it is our reluctance, our inability, to tolerate being demoted to the backseat. Spurred by our success in programming our children during the preschool years, we may find it difficult to forgo in later states the level of control that once afforded us so much satisfaction.
    Melinda M. Marshall (20th century)