Implementation

The implementation of the plug and play architecture is closely related to the use design patterns, specifically to creational and behavioral patterns. A plug and play architecture for the Kraalingen approach should allow the flexibility to replace the basic class/components (i.e., Soil, Plant, and Weather) with other components that provide similar behavior and implement the same set of interfaces as the exiting class/components [Pap05]. In Section 7.2, Communication control-entity, in Chapter 8, we mentioned that the control object communicates with entity objects through interfaces. Therefore, any class implementing the interface could be used in the system. It is desirable to have a mechanism that allows for substituting a class/component with another similar one that does not require changes of code. Ideally, such a mechanism would make the choice of the class/component to be used at run time. The problem of selecting among many potential class/components is solved by the Strategy pattern, presented in Section 5.2 of Chapter 7. The strategy pattern used for implementing the plug and play architecture is shown in Figure 9-1.

Weathe iDat aFromFile

^getTemperatureMinimum() ^getTemperatureMa»mum(}

%etRainfalti) ^getScfarRadiation()

WeatbeiDai aFromStati on

^getTemperatureM!nimum() ^getTemperaîureMaximumf) ♦getRainfall()

%et Sol arRadiationQ_

WeatherOataFromDatabase

^getTemperatureMinimuO ^getTemperatureMaximum( ) ♦getRainfelK)

%etSolarRadiation{)

Weathe iDat aFromFile

^getTemperatureMinimum() ^getTemperatureMa»mum(}

%etRainfalti) ^getScfarRadiation()

WeatbeiDai aFromStati on

^getTemperatureM!nimum() ^getTemperaîureMaximumf) ♦getRainfall()

%et Sol arRadiationQ_

WeatherOataFromDatabase

^getTemperatureMinimuO ^getTemperatureMaximum( ) ♦getRainfelK)

%etSolarRadiation{)

Figure 9-1. Strategy pattern used for implementing a plug and play architecture.

Selecting for use a class at run time requires a mechanism for dynamically creating instances of used classes. The AbstractFactory pattern will be used for this purpose. The Java implementation of the patterns used is closely related to the concept of Reflection, discussed in the next section.

0 0

Post a comment