Info

15 //used to set relationships with other classes

16 public void setWeather(IWeather weather);

17 public void setSoil(ISoil soil);

18 //used to provide simulaton results to users

19 public double getFruitDryWeight();

20 public double getRootDryWeight();

21 public double getTotalPlantDryWeight();

Figure 8-28. Java implementation for interface IPlant (Part 2 of 2).

Lines 4, 15, and 19 are comments or stereotypes, defined in Section 11 of Chapter 3 in the first part of the book. They define a specific categorization for the methods that follow the comment or stereotype. Thus, the method integrateQ, as defined in line 8, belongs to the category referred to as used by the simulator controller. Methods defined in lines 20, 21, and 22 belong to the category used to provide simulation results to users. Methods defined in the interface IPlant are classified in three categories. Classifying methods of an interface in different categories helps one to understand the role of the interface and its behavior. Therefore, we can say that interface IPlant is designed to provide three kinds of behaviors: Behavior needed in the simulation process, behavior needed to establish relationships with other classes of the diagram, and behavior to provide simulation results to other objects in the system.

How do we define the behavior of an interface? The behavior of an interface is defined by considering the role classes implementing the interface should play in the system. Interfaces should define one specific role and be defined in its entirety. Two different interfaces should not share common behavior. Designing an interface is a delicate process and needs to be carried out carefully. Interfaces that provide many different behaviors should be avoided. The behavior of such interface should be distributed to other interfaces.

In the case of the class Plant, its interface should define all the functions that module Plant must provide as defined by [Kra95]. As previously mentioned in this chapter, module Plant should be able to perform processes referred to as initialization, rate calculation, and integration. Therefore, the interface IPlant includes methods initializeQ, calculateRateQ, and integrateQ, as defined in lines 5 through 8. Note that this interface defines two methods that hold the same name, initialize, but with different signatures. The reason for having the same method definition with different signatures is to allow more flexibility in the initialization process of class Plant. The method initializeQ, with no parameters, can be used in cases when users do not provide any initial plant data. In this case, the default data will be used and the initializeQ method will be activated. The method initialize(Properties props) will be used when users want to study the effect of different parameters on plant growth. As an example, the planting date is a parameter that impacts plant growth. This parameter and can be stored in the property file props and be used as an entry parameter for the simulation process. In the case that other plant parameters need to be used to study their impact on plant growth, they need to be added to the property file. The following is an example of a property file.

plantingDate=121

soi1Depth=14 5

wi11ingpoi ntPercent=0.06

Method getLeafArealndexQ , defined in line 9, provides information about the leaf area index needed to calculate processes that occur in soil. Methods defined in lines 10 through 13 provide information about the status of the plant; the use of method isMatureQ defined in line 12, will allow other objects to know whether plant has reached the status of maturity. When the plant reaches the status of maturity, the attribute that holds the value of the maturity day needs to be updated. The update process is carried out by the method referred to as setMaturityDayQ. Method isPostPlantingQ checks whether the current day in the simulation process is after the planting date. Methods belonging to stereotype used to set relationships with other classes allow an object of type Plant to have access to objects of type Soil and Weather. Methods belonging to stereotype used to display simulation results represent the behavior that allows an object of type Plant to provide results of the simulation to other objects that may request for these data. The object that is most interested to know the results of the simulation is the boundary object referred to as SimulationForm object. This object performs the task of communicating with the controller object in order to provide initial values used in the initialization process of plant, soil, and weather and the task of receiving the results of the simulation to display them to the user. In the case that additional plant results are needed, then the necessary methods will be added to the interface definition. As shown in Figure 8-28, interface IPlant defines methods that provide dry weight data for the fruit, the root, and the total plant. Any class Plant that will be considered for use in our system should implement interface IPlant. Figure 8-29 shows the UML diagram representing the association between class Plant and its interface IPlant.

0 0

Post a comment