Convert Attributes to Properties or Generate Getter/Setter Methods

In this guide, we'll learn how to convert class attributes to properties, adjust their naming conventions, and set their visibility. We'll also explore how to create getter and setter methods for specific attributes. This skill is essential for organizing and refining your UML diagrams.

Initial Setup

Before diving into the steps, let's outline our starting point within Software Ideas Modeler. This section provides a snapshot of the existing class diagram setup we'll be working with.

  • Diagram Type: UML Class Diagram
  • Class in Focus: Document
  • Attributes of the Document class:
    • id : Integer
    • author : String
    • name : String
    • description : String
    • isShared : Bolean
    • content : Object

These attributes are private and form the basis of our demonstration for converting to properties and applying further modifications.

Step 1: Selecting Attributes for Conversion

  • Open your class diagram and locate the class 'Document' which contains several attributes.
  • To convert these attributes into properties, you first need to select them. This can be done in two ways:
    • Method 1: If the attributes are not adjacent to each other, hold the CTRL key and click on each attribute individually.
    • Method 2: For consecutive attributes, click on the first attribute, press and hold the SHIFT key, then click on the last attribute. This selects all attributes in the range.

Step 2: Converting Attributes to Properties

  • Right-click on the selected attributes to open the context menu.
  • Navigate to 'Stereotypes' and select 'property'.
  • This action annotates your chosen attributes with the 'property' stereotype and changes their visibility to public.

Step 3: Updating Property Naming to Pascal Case

  • Go to the 'Field' ribbon tab and locate the 'Adjust Names' dropdown in the Field group.
  • Click on it and choose 'Pascal Case'.
  • This updates the naming convention of all selected properties to Pascal Case.

Step 4: Changing Property Visibility

  • Sometimes, you might need properties to be non-public. For example, to change the 'Id' property to protected:
    • Right-click on the 'Id' property.
    • In the context menu, navigate to the 'Visibility' submenu and select 'Protected'.
    • This changes the 'Id' property's visibility to protected.

Step 5: Adding Getter and Setter Methods

  • Finally, let's address the 'Content' attribute.
  • Right-click on 'Content' attribute and choose 'Add Getter and Setter' from the context menu.
  • This automatically adds two operations, 'GetContent' and 'SetContent', with appropriate return types and parameters, to the class.

New Comment

Comment