Home > Articles > Programming > C#

This chapter is from the book

4.6 UML Class Diagram with a Property

Figure 4.9 contains an updated UML class diagram for the version of class GradeBook in Fig. 4.7. We model properties in the UML as attributes—the property (in this case, CourseName) is listed as a public attribute—as indicated by the plus (+) sign—preceded by the word "property" in guillemets (« and µ). Using descriptive words in guillemets (called stereotypes in the UML) helps distinguish properties from other attributes and operations. The UML indicates the type of the property by placing a colon and a type after the property name. The get and set accessors of the property are implied, so they're not listed in the UML diagram. Class GradeBook also contains one public method Display-Message, so the class diagram lists this operation in the third compartment. Recall that the plus (+) sign is the public visibility symbol.

Fig. 4.9

Fig. 4.9 UML class diagram indicating that class GradeBook has a public CourseName property of type string and one public method.

A class diagram helps you design a class, so it's not required to show every implementation detail of the class. Since an instance variable that's manipulated by a property is really an implementation detail of that property, our class diagram does not show the courseName instance variable. A programmer implementing the GradeBook class based on this class diagram would create the instance variable courseName as part of the implementation process (as we did in Fig. 4.7).

In some cases, you may find it necessary to model the private instance variables of a class. Like properties, instance variables are attributes of a class and are modeled in the middle compartment of a class diagram. The UML represents instance variables as attributes by listing the attribute name, followed by a colon and the attribute type. To indicate that an attribute is private, a class diagram would list the private visibility symbol—a minus sign ()—before the attribute's name. For example, the instance variable course-Name in Fig. 4.7 would be modeled as "- courseName : string" to indicate that it's a private attribute of type string.

  • + Share This
  • 🔖 Save To Your Account