Jump to Menu

How to Edit an Attribute's Initial Value

Initial value defines the default value for attribute when the owning object is instantiated. You can give a text value for initial value, or select a public attribute from other classes. In this tutorial, you can study how to define default value for attribute of a class and then share the same default value with another class.

Compatible edition(s): Enterprise, Professional, Standard, Modeler

  • August 16, 2010
  • Views: 41,533
  • PDF

  1. Create a new project by selecting Project > New from the application toolbar. In the New Project window, enter A Simple Model as project name and click Create Blank Project.
    New project
  2. Create a class diagram by selecting Diagram > New from the application toolbar. Select Class Diagram and click Next.
    New class diagram
  3. Click OK to confirm.
  4. Create a class by selecting Class from the diagram toolbar in advance and clicking it on the diagram. Name it as COLOR. In some programming languages, a constant class is named in upper case.
    Create class
  5. Although COLOR is constant class, you can set it to be a static class. Right-click on the class and select Open Specification... from the pop-up menu.
    Open class specification
  6. In the Class Specification window, open Class Code Details tab and check final and static. Next, click OK button.
    Check static
  7. COLOR contains several attributes for different colors. Let's create an attribute for red. Right-click on COLOR and select Add > Attribute from the pop-up menu.
    New class attribute
  8. Enter +red : int = 1 and press Enter to confirm. Entering + means you set it as public, thereby, it becomes accessible to other classes. Here red is the name of attribute while 1 is the default value.
    Inline editing class attribute
  9. Similarly, enter green : int = 2 and blue : int = 3 respectively. The image below shows the result:
    Attribute created
  10. Since the three colors are static, you'd better set their scope to be classifier. Select all the three attributes, right-click on them and select Model Element Properties > Scope > Classifier from the pop-up menu.
    Set attribute scope
  11. Now, create another class through diagram toolbar and name it as Shape.
    Shape class created
  12. Add an attribute and then name it as color : int, press Enter and then Esc to confirm.
    Color attribute created
  13. Let's customize the default color of shape as green. You have to set the initial color for the color attributes as COLOR.green in advance. Right-click on the attribute color and select Open Specification... from the pop-up menu.
    Open attribute specification
  14. In the Attribute Specification window, open General tab. Press the upside down arrow in the Initial value field to select green : int in the tree. Click OK to close the specification window. Note that only public attributes are available to select as the initial color.
    Select initial value
    The result of Shape class is shown as follows:
    Initial value selected


Turn every software project into a successful one.

We use cookies to offer you a better experience. By visiting our website, you agree to the use of cookies as described in our Cookie Policy.

OK