Collective Behavior



 Shark shark = new Shark();
 Collection<Fish> swarm = new ArrayList();
 for ( ... ) swarm.add(new Fish());


Swarm Behavior is a new composition operator that associates behavior with a collection of instances. The lookup of swarm behavior is based on the element type of a collection and is thus orthogonal to the collection hierarchy.

The method mimicryAttack

  • is defined in the lexical scope of the Fish class,
  • is available for all subtypes of Collection, but
  • limited to collections that contain Fish instances.
  • can be overridden by subclasses of the Fish class.


NB, useful for both static and dynamic languages.


  • Adrian Kuhn, David Erni, Marcus Denker, "Empowering Collections with Swarm Behavior," to be submitted to somewhere sometimes, (mail us to get a copy).



Last changed by admin on 21 April 2009