Info

5 private Plant plant;

6 private Soil soil;

7 private Weather weather;

8 private SimulationController() {}

9 public SimulationController getlnstance() {

10 if (uniquelnstance = null)

11 uniquelnstance = new SimulationController();

12 return uniquelnstance;

Figure 8-22. Java class definition for SimulationController.

The fact that the control object is directly connected to entity objects makes the architecture of the system rigid. When two or more objects are directly linked to each other, none of them can be used separately; the use of one of the objects would require the presence of the others. This architecture is not flexible as it makes it difficult for either the control or entity objects to be reused separately.

The solution to this problem is to avoid linking classes directly; instead, an interface to the class can be used as shown in Figure 8-23. Interface IPlant defines the behavior class Plant should implement. This behavior includes operations such as initialize, calculateRate, and integrate. Interface ISoil defines the behavior class Soil should implement.

Figure 8-23. The control object communicates with entity objects through interfaces.

Connecting the control class to the interfaces instead of the entity classes opens possibilities to use any other entity class or component that offers similar behavior, provided that they implement the same interface as shown in Figure 8-24.

Q>IPIant plant <%>ISoil soil eat her weather

%imulate(}

^simulateiProperty properties)

%imulate(}

^simulateiProperty properties)

OtherPiant

Plant

QtherSoil

Soil

OtheiWeather

Weather

Figure 8-24. Interfaces allow for plugging in other class/components.

OtherPiant

Plant

QtherSoil

Soil

OtheiWeather

Weather

Figure 8-24. Interfaces allow for plugging in other class/components.

0 0

Post a comment