Defining the attributes
You are now ready to implement your design in the Public Interface Editor. Begin by defining the attributes of your runner part. A part's attributes typically correlate to the part's Attribute data types and can additionally include derived attributes, or attributes that are determined based on the value of other attributes.
In the Public Interface Editor, on the Attribute page of the notebook, do the following:
1. Type number in the Attribute name entry field and select the Add with defaults push button.
Your Public Interface Editor will look like this:
Notice that several default values are displayed:
a. number is the default Get selector and matches the number method of your design. When your runner part is asked for the value of its number attribute, it will run the number method to answer the number that has been assigned to the runner for the race.
b. Likewise, number: is the default Set selector. When your runner part is told the number that has been assigned to it for the race, it uses the number: method to store the value in its number attribute.
c. number is the default Change event symbol. Whenever a value is stored in the number attribute using the number: set selector, the runner part signals this event to let other parts know that the value has changed. For example, if there is an attribute-to-attribute connection between number and a label's string value, the label part will be informed so that it displays the latest value.
d. Object is the default Attribute data type. This means that the number attribute must be an instance of the Object class.
2. You can change any of the default values if you need to. Change the value in the Attribute data type field to String, because in this example the runner's number is a simple three-character string of numerals, and select the Update push button.
3. Repeat the previous steps for the runner's finishTime attribute. Type finishTime as the Attribute name. Select Add with defaults, and change the Attribute data type to Time, because the runner's finish time is a time.
4. The runner also has one derived attribute, asResultString. Type this attribute name but do not select Add with defaults. Instead, enter asResultString as the Get selector, enter runnerChanged as the Change event symbol, and enter String as the Attribute data type. Ensure the Set selector is blank. Then, select the Add push button.
Every time the runner part receives the runnerChanged event, it will refresh the value of its asResultString attribute by running the asResultString get selector. Because there is no set selector, the attribute is read-only, so other parts cannot set it.
Now is a good time to save your work. Select Save Part from the File menu.
Last modified date: 07/15/2020