Info

3 public interface ISimulationController {

4 public void simulate(Properties props);

5 public Properties getSimulationResults();

Figure 8-38. Definition of interface ISimulationController in Java.

As shown in Figure 8-38, the interface ISimulationController defines the behavior that needs to be implemented by all classes that are candidates to play the role of the controller in the simulation process. Line 4 defines the method simulate(Properties props) that passes to a SimulationController object a parameter of type Properties that holds the initial values to be used for instantiating objects of classes Plant, Soil, and Weather. Line 5 defines the method getSimulationResultsQ that will be used by the boundary object to obtain the result of the simulation. Therefore, SimulationController will store the results of the simulation in an object of type Properties.

It is important to note that the provided solution establishes a communication bridge only between the boundary and controller objects. The boundary object does not have access to entity objects such as plant, soil, or weather. The boundary object can communicate to all controller objects, provided they implement the required interface as defined in Figure 8-38. Figure 8-39 shows the implementation of class SimulationController in Java.

In this figure, line 1 shows that class Properties is imported from the Java library system. Line 3 defines class SimulationController using the Singleton pattern and implementing the interface ISimulationController. Line 4 defines an attribute of type SimulationController referred to as uniquelnstance, as this attribute will hold the unique instance of the class. Lines 6, 7, and 8 define attributes of types IPlant, ISoil, and IWeather that respectively reference objects plant, soil, and weather. Line 9 defines an attribute of type Properties that is used to hold the results of the simulation. Lines 11 through 24 define a constructor for the class. As the class is modeled using the Singleton pattern, the constructor is private, meaning that no other object in the system can call this method. Therefore, only one instance of the class can be created. Lines

12, 13, and 14 create instances for objects plant, soil, and weather. The corresponding classes Plant, Soil and WeatherDataFromFile, implement the required interfaces: IPlant, ISoil, and IWeather.

1 import java.util.Properties;

0 0

Post a comment