Adding Variables to Classes

Home Up Search Java 2 API C++ Resources

The instance variables (properties) in a class can be manipulated using the Properties Dialog of the desired class.

  1. Double click the class in the class diagram.
  2. Select the "Variables"  tab.
  3. Click on "New" to create a new variable or select the desired existing variable.
  4. The variable type can be typed in or selected from the drop list.
  5. Click on the "Initial Value" tab to set the default value for the variable. 
    1. Type in the initialization code without either the "=" sign or the ending semicolon, e.g.:
            new Rectangle(5,17)    (to initialize to a new object instance)
      or
            56.294  (to initialize to a specific primitive value)
  6. Click on the "Comment" tab to write a description of the variable.
  7. Select the proper scoping ( package, public, protected, private) and whether the variable is static, final, etc from the radio button choices.
  8. If an accessor method is desired for this variable, select the "Properties" tab and then if a "get" and/or "set" routine is desired.   SB will automatically generate the accessor method.