Interface myphysicslab.lab.util.Parameter

Provided By
All Extended Interfaces
All Known Subinterfaces
All Known Implementations

Provides access to a value of a Subject and meta-data such as name, a set of possible values, or whether it is editable. Part of the Observer design pattern which ensures that change notification operates correctly even when any of several objects can potentially change the value.

See myphysicslab.lab.util.Subject for more documentation about how Subject, Observer and Parameter work together.

A Parameter of a Simulation is a value that usually doesn't change during the running of the Simulation. For example, gravity would not change while running the Simulation; however an outside entity like the user can change the gravity as the Simulation is running.

A Parameter makes its value easily accessible to a user interface control like NumericControl, ChoiceControl, or CheckBoxControl. Using a Parameter ensures that those controls display the correct value because the Parameter is broadcast to all Observers of the Subject whenever the value changes.

Parameter helps to minimize how much knowledge classes have about each other. For example, a NumericControl can be set up to display and modify the ParameterNumber of a Subject without knowing anything about the Subject other than that it implements the Subject interface.

Getter and Setter Methods

A Parameter operates by calling getter and setter methods on its Subject. These methods are specified to the Parameter's constructor, and used in the Parameter's #getValue and #setValue methods. We assume that the Subject's setter method will perform notification of changes via Subject.broadcastParameter.

Here are examples of getter and setter methods showing how the Parameter is broadcast in the setter method of the Subject.

SingleSpringSim.prototype.getMass = function() {
  return this.block_.getMass();

SingleSpringSim.prototype.setMass = function(value) {

Here is an example showing how the getter and setter methods are specified when creating a ParameterNumber. This is from the SingleSpringSim constructor:

this.addParameter(new ParameterNumber(this, SingleSpringSim.en.MASS,
    SingleSpringSim.i18n.MASS, this.getMass, this.setMass));

Choices and Values

It is optional for a Parameter to have a set of specified choices and values. If they are specified, then the Parameter value is only allowed to be set to one of those values.

When the set of Parameter choices is changed, a GenericEvent should be broadcast with the name #CHOICES_MODIFIED. Then any control that is displaying the available choices can update its display.

Instance Methods