All about 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.

August 16, 2010
User Rating: / 1
Views: 1,909
PDF Link Add comments
Edition: Community or above (Edition comparison)

  1. Create a project with starting VP-UML. Select File > New Project from the main menu. In the New Project dialog box, enter in A Simple Model as project name and then click Create Blank Project button to continue.
    new project
  2. Create a class diagram by right clicking on Class Diagram in Diagram Navigator and selecting New Class Diagram from the pop-up menu.
    new class diagram
  3. 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
  4. 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
  5. In the Class Specification dialog box, open Class Code Details tab and check final and static. Next, click OK button.
    final static
  6. 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 attribute
  7. 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.
    enter attr name
  8. Similarly, enter green : int = 2 and blue : int = 3 respectively. The image below shows the result:
    color constant
  9. 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.
    select classifier
  10. Now, create another class through diagram toolbar and name it as Shape.
    shape class
  11. Add an attribute and then name it as color : int, press Enter and then Esc to confirm.
    shape class with color attr
  12. Let 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.
    new attribute in shape
  13. In the Attribute Specification dialog box, 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 dialog box. Note that only public attributes are available to select as the initial color.
    select green
    The result of Shape class is shown as follows:
    final shape class

Rate this Article

Click on one of the stars below to rate this article from 1 (lowest) to 5 (highest).

You may be interested in

  1. Writing Effective Use Case
  2. Draw Entity Relationship Diagram (ERD)
    Tagged:
  3. UML Package Diagram
    Tagged:
  4. Produce UML Use Cases from Business Process Diagram (BPD)
  5. Oracle database design with Entity Relationship Diagram
Tags of this article:

Comments (0)

Write comment

Rating

Comment

Enter the calculation result

security code