How to Create a UML Class Diagram

A step-by-step guide on creating a UML class diagram using Software Ideas Modeler. This tutorial will walk you through the process of building a comprehensive class diagram, including adding classes, attributes, operations, and defining relationships.

Creating a New Empty Class Diagram

  • Navigate to the Insert Tab:
    • Go to the ribbon at the top of the screen and click on the "Insert" tab.
  • Insert to Project:
    • In the "Project" group, click on the "Insert to Project" button.
    • From the dropdown menu, select "Add New Diagram."
  • New Diagram Dialog:
    • In the dialog that appears, choose "Class Diagram" from the UML group.
    • Enter the name "Products" for your new diagram.
    • Click on the "OK" button to create and open the new diagram in the main window.

Adding the First Class

  • Locate the Class Tool:
    • Find the Class tool in the toolbox on the side of the screen.
  • Add the Class:
    • Drag the Class tool button onto the canvas and release it to create a new class.
    • Name this class "Product."

Adding Attributes to the Class

  • Add Attributes:
    • Select the "Product" class on the canvas.
    • Press the Down key to add a new attribute.
    • Type "ProductNumber: String" and press Enter.
  • Repeat for More Attributes:
    • Add attributes "Name: String," "Description: String," and "Price: Double" using the same method.

Adding Operations

  • Add Operations:
    • Press CTRL + Down key (or click on the Add Operation button in the context bar) to start adding an operation.
    • Enter the operation name "Activate."
  • Repeat for More Operations:
    • Add operations "Deactivate" and "AddToCategory(c: Category)" using the same method.

Understanding Visibility

You can define the visibility of attributes and operations using the visibility symbols, just by entering the character before the name of an attribute or operation or you can right-click on the field and choose the desired option from the Visibility submenu.

These visibilities are supported by UML standard:

  • Minus (-) for private
  • Hash (#) for protected
  • Tilde (~) for package
  • Plus (+) for public

Adding Subclasses

  • Add Subclasses:
    • Select the "Product" class.
    • Use the context bar button "Add Sub Class" to create subclasses.
    • Name the subclasses "Laptop" and "Smartphone."
  • Add Attributes to Subclasses:
    • For "Laptop," use the context bar or press the '2' key to add the attribute "HasTouchScreen: boolean."
    • For "Smartphone," use the context bar or press the '2' key to add the attribute "HasStylus: boolean."

Implementing an Interface

  • Add Interface Realization:
    • Right-click and drag the "Product" class.
    • Choose "Add Interface Realization" from the context menu.
    • Name the interface "IProduct."

Exploring Aggregation Relationship

  • Add Category Class:
    • Add a new class named "Category" to the diagram.
  • Use the Aggregation Tool:
    • Select the Aggregation tool from the toolbox.
    • Click on the "Category" class and drag to the "Product" class to connect them.
  • Define Roles and Multiplicities:
    • Click on the label near the "Category" class and set the start role to "parentCategory" with multiplicity "1."
    • Click on the label near the "Product" class and set the end role to "products" with multiplicity "*" (many).
  • Name the Relationship:
    • Click on the label in the central part of the relationship line and enter its name "Categorization."

Adding Self-Aggregation to the Category Class

  • Create Self-Aggregation:
    • Select the Aggregation tool and drag it from the toolbox directly onto the "Category" class.
  • Define Roles and Multiplicities:
    • Click on the label near the aggregation point and set the start role to "parentCategory" with multiplicity "0..1."
    • Click on the end role label and set it to "subCategories" with multiplicity "*" (many).

Exploring Usage Relationship

  • Add PriceSetter Class:
    • Add a new class named "PriceSetter" to the diagram.
  • Use the Usage Tool:
    • Select the Usage connector tool from the toolbox.
    • Click on the "Product" class and drag towards the "PriceSetter" class to create a Usage relationship.

New Comment

Comment