Enabling conditions are the control structures
of model programs. Writing enabling conditions is the only way to control the
sequence of actions that can occur when a model program executes. When coding
enabling conditions, it is helpful to refer to the sample traces you wrote during
preliminary analysis.
An enabling condition is a Boolean method that returns a bool value (a Boolean
method is sometimes called a predicate). The enabling conditions of an action
method have the same name as the action method, with the added suffix Enabled.
An action method that has no enabling condition is always enabled (as if it had an
enabling condition that always returned true).
An enabling condition describes a set of states: all the states where it returns true.
In this example, the enabling condition for the ShowTitles action method (described
before) is ShowTitlesEnabled. It expresses that ShowTitles is enabled in all states
where the page is a Topics page and the style is WithText. In this model program,
there are two such states, where the third state variable sort takes on both of its two
possible values.
static bool ShowTitlesEnabled()
{
return (page == Page.Topics && style == Style.WithText);
}
Enabling conditions may have parameters, which correspond to the parameters
of its action method. The parameters in the two methods are matched up by order,
so the first parameter in each must have the same type (etc.
Pages:
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113