We are creating an instance of a class that implements
ApplicationStateCreator, and in this case the interface is associated with the
IDataSource type??”the type we are going to use for our ASO. We don't even care
to name the class which is used to create the instance, so it remains anonymous:
... = new ApplicationStateCreator
()
{
...
}
Chapter 4
[ 125 ]
The ApplicationStateCreator interface has only one method, create(). This
method should return an instance of the type with which the interface is associated,
and this is exactly where we define which class should be instantiated for the ASO.
You can also do some custom configuration in this method if you need like, obtain
some resources, pass them as parameters to the class constructor, and so on. In our
case this method is very simple:
public IDataSource create()
{
return new MockDataSource();
}
If you later create another implementation for the data source, you will have
to change one single line to make the new data source available throughout
the application:
return new RealDataSource();
Finally, we add the new creator to the application's configuration and, once again,
associate it with the type of ASO that the creator should be used for.
Pages:
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171