Factory pattern
The factory pattern creates a new monitor instance to handle each new item/request. Its essential features include:
The
onload() action sets up an event listener for creation events,
Each creation event causes a monitor instance to be spawned.
There are two common forms of the factory pattern:
Canonical form
The monitor instance spawns to an action that initializes the state of the new monitor instance and creates event listeners specific to that monitor instance. The spawned monitor instances use local variables for coassignment and passes them into the action.
It is likely that some of the data from the creation event is copied into global variables.
Alternate form
The initial monitor instance uses coassignment to global variables to set some state before spawning.
This is a "lazy" form in that it stores the complete creation event inside the monitor. You should not use this form if you are spawning large number of monitor instances and you have a large creation event, where only part of the creation event data needs to be retained.
As an exercise, consider rewriting the example in
Translation using spawning, to use the alternate factory form.
Copyright © 2013
Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.