Stereotypes

A stereotype is rendered as a name enclosed by guillemots and placed above the name of another element [BRJ99]. Figure 3-16 shows an example of a stereotype.

Accounting

Figure 3-16. Example of stereotype.

The stereotype in Figure 3-16 is the word «subsystem» that gives to the package Accounting a special meaning or classification. Without the stereotype, the package Accounting is a general package. The stereotype allows the designer to create a new modeling element. Therefore, as shown in Figure 3-16, the stereotype converts a general package into a subsystem, thus creating a new building block.

Stereotypes can be used to group operations of a class into different categories, helping users to understand the context in which an operation is used. Figure 3-17 shows that operations of class Plant are grouped in two categories: Initialization and query. Thus, operations setBaseTemperature, setFractionToCanopy, and setPlantDensity belong to the category initialization. Operations isMature and isPostPlanting belong to the category query. In the case that some changes have to be done to the initialization process, it is easy to locate the corresponding operations. Figure 3-17 shows that class Plant belongs to the group of entity classes, used to represent concepts of the problem domain. (We will see more about entity classes in Part two of the book.)

Plant

"^«initialization» setBaseTemperatureQ ^«initialization» setFractionToCanopyQ ^■«initialization» setPlantDensityQ ^«query» isMaturef) ^«query» isPostPlantingf)

Figure 5-/7.Using stereotypes to classify operations.

Stereotypes can be implemented in Java as comments. Figure 3-18 shows an example of using comments to translate the UML stereotypes in Java code. Figure 3-18 shows only part of the Java implementation of class Plant, the part related to the stereotype definition.

1 public class Plant {

0 0

Post a comment