Collecting Parameter
From CSSEMediaWiki
Revision as of 00:35, 20 October 2010 by Oliver Cardwell (Talk | contribs)
Collecting Parameter
This idiom describes when a collection is repeatedly passed as a reference along a structure, each element is then responsible for adding items to the collection.
Real World Example
Someone making a collection, lets say a church collection, passes the collection plate to the person sitting next to the isle in each row. They can then place some money onto the plate before passing it to the person sitting next to them, and so on.
Pseudo Code Example
This example code finds all the 'good' employees in each department. It passes the collection (list of employees) to each department and they can decide who they think are good employees.
List<Employee> goodEmployees = new List<Employee>(); foreach (Department department in Company){ department.GoodEmployees(goodEmployees); // adds good employees to the collection } print(oldEmployees);