State
variables that are used by more than one feature should be declared in a class that is
not a feature, so they will always be included.
Figure 7.3 shows excerpts from a version of the client/server model program
where the client and server are separate features (compare to the original version in
Chapter 5, Figures 5.7??“5.10). All of the state variables are used by both the client
and the server, so they remain in the ClientServer class, which is not a feature. The
state variables are declared internal to make them accessible in the feature classes.
The action methods and enabling conditions of the client and server are declared in
the new Client and Server classes, which are features.
7.2.2 Including or excluding features
Features are included in a model program by naming them in the LibraryModel-
Program constructor (Chapter 6, Section 6.2.1). This constructor has an optional
third argument, a set of strings that name the features to include. If this argument
is omitted, all features are included. You can write several factory methods, where
each one names a particular combination of features. When you invoke a tool, use
the factory method that names the features you want to include.
In Figure 7.3, the factory method CreateServerOnly names the server feature but
not the client. This command runs mpv on the client/server model program with just
the server feature included.
Pages:
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179