If the reader inspects just a few of the sample Swarm programs, the importance of the building objects should become apparent. Objects are named and memory is set aside for them in this stage. In the buildObjects method, one typically finds commands that not only create the objects being used in the current class, but there will also be a command which instructs the next-lower level of agent to create its objects.
Consider the rich example provided by the code from the Arborgames model. In the buildObjects method of the observer swarm, one finds a large number of commands that create graphical display objects (objects subclassed from the graph library). One also finds commands that create the simulation control panel, which will appear on the screen and offer the user the ability to start and stop the simulation.
It is vital to note also that the buildObjects method in the observer swarm file triggers the creation of the next lower level of agents. It creates a memory zone and creates a model swarm in that memory zone. Using the current style, the code would look like so:
Objective C example | Java example | ||
---|---|---|---|
|
|
In the Objective C case only, users may find older versions of this code which accomplish the same purpose, but are slightly more verbose and do not take into account the fact that the observer swarm object is itself a memory zone.
modelZone = [Zone create: [self getZone]]; forestModelSwarm = [ForestModelSwarm create: modelZone]; [forestModelSwarm buildObjects]; |
Note the importance of the last line in either of these excerpts. The first line of the code creates the model swarm object (in this case, it is called forestModelSwarm), but the last line tells that object to create its own objects by telling the forestModelSwarm to execute its own buildObjects method. To find out what that implies, one must go look in the implementation file (or .java file in the Java case) for the ForestModelSwarm to see what objects it creates.