Adding the parts
An object factory is a nonvisual part provided with VA Smalltalk that is capable of dynamically creating new instances of a specified part. In
Creating a reusable nonvisual part, you created a
Runner part, and in
Creating a reusable visual part, you created a
RoadRaceView that enabled you to see the results of a single runner in a road race. Let's expand on these examples by using an object factory to create many runners in a road race.
Open the Composition Editor on the RoadRaceView visual part that you created in the earlier section.
In the Composition Editor, remove the
Result Text part and the
runner nonvisual part. Add a list named
Result List and a push button named
RecordPB to make your window part look similar to the following:
Adding the object factory
Add an Object Factory part, to the open space of the free-form surface. Open the settings of the Object Factory part and set the instanceClass to Runner and the partName to Runner Factory. instanceClass specifies the class of object for which the object factory will create instances. Close the settings when your changes are complete.
Select Connect > All Features from Runner Factory's pop-up menu. Notice that the three attributes, number, finishTime, and asResultString you defined for your Runner part are listed in the attributes list. Also notice that the attributes, actions, and events of an Object Factory part, such as new and instance, are listed. Close the Start connection from window by clicking Cancel.
Adding the ordered collection
An ordered collection is a nonvisual part provided with VA Smalltalk that can contain an ordered group of related objects. You will use an ordered collection in this example to contain the group of runner objects as each is created by the Runner Factory.
Add an Ordered Collection part, to the open space of the free-form surface. Change the name of the ordered collection to Runners Collection.
Select Connect > All Features from Runners Collection part's pop-up menu and examine some of the attributes, actions, and events of an ordered collection. Notice that you can ask for the size of the ordered collection and the first and last items in the collection, and add an item or remove an item from the collection. Close the Start connection from window by clicking Cancel.
Last modified date: 07/15/2020