Class diagrams let you create, organize, and inspect the classes and associations in an MDriven model; use them when you want to describe the structure of the domain you are building.
A class diagram is a UML (Unified Modeling Language) view of part of your model. In MDriven Designer, the diagram is a presentation of model elements, not the model itself. You can place the same class on several diagrams and show different details in each one.
For example, you might use one diagram to show a House, its address, and its relation to Street. On another diagram, you can place the same House class but show only its state-related features.
Understand classes, features, and associations
A class defines a domain concept. Objects are instances of that class. A class can have attributes, methods, and associations.
| Element | Meaning in a class diagram | Example |
|---|---|---|
| Class | A domain concept and its definition. | House
|
| Attribute | A typed piece of information held by an instance of a class. | Address : String
|
| Method | An operation defined for the class. | A method that performs an action on a House.
|
| Association | A relationship between two classes. In MDriven, another model class is related through an association rather than used as an attribute type. | House associated with Street
|
A class is shown as a box. The box can display the class name and selected features, such as attributes, associations, and methods. The details shown are controlled per diagram, so a concise overview does not have to expose every feature of a class.
Work with class diagrams in MDriven Designer
Create a class on a diagram
- Open the diagram where you want to work.
- Right-click the diagram background and select Add a class.
- Name the class. You can also select its name and press
F2, or double-click the name, to edit it. - Select the class to inspect and change its properties in the Object Inspector.
A newly created class belongs to a package. Packages can be used to section the software system, similarly to namespaces. A model can use multiple packages, but it does not require them.
Add an attribute
- Select the class in the diagram.
- Press
Ctrl+Ato add an attribute. - Double-click the attribute to give it a name, such as
Address. - Select the attribute and choose its type in the Object Inspector.
An attribute needs a type. If an attribute allows a null value, MDriven presents this as Allow NULL. In generated C#-style notation, a nullable type is shown with ?; for example, String? indicates an attribute that allows NULL.
Create an association between classes
Use an association to relate one class to another.
- Place both classes on the diagram.
- Choose the Association mode tool.
- Drag from one class to the other.
- Select the association to edit its properties in the Object Inspector.
For example, create an association between House and Street when a house belongs in a street. The association labels can be controlled in the diagram settings. Association names that are inferred from what they point to can be shown dimmed with DimDefaults, shown normally with AlwaysEvenDefaults, or omitted with NoDefaults.
For a clearer layout, use square association lines. Select the diagram background, then set square new associations in the Object Inspector to make new associations use square lines by default. You can also drag an association to introduce routing points and arrange the line around other elements.
Place the same class on multiple diagrams
A diagram may contain any, all, or none of the classes in the model. A class can appear on any number of diagrams.
To reuse a class, drag it from the repository tree onto another diagram. This creates another representation of the same model class; it does not move or duplicate the class in the model. Changes to the class itself, such as adding an attribute, are therefore available wherever that class is shown.
Use this to make focused diagrams. For example:
- On a Property overview diagram, show
House,Street, and their association. - On a House lifecycle diagram, show
Housewith onlyAddressandStatevisible.
For a broader introduction to diagrams and the repository tree, see MDrivenStart:MDrivenStart Diagrams and Documentation:MDriven designer overview Part 1.
Control what the diagram shows
Showing or hiding a feature changes the current diagram view. It does not remove the feature from the class or repository.
- Right-click a class on the diagram.
- Select Features and then Pick show featuresâŚ.
- In the Featurepickform, select a display mode: show all, show only picked, hide only picked, or hide all.
- Pick the attributes or other features to display.
For example, choose show only the picked and select Address and State. Those features remain visible on this diagram while the remaining attributes remain in the model and can still be visible on other diagrams.
You can also select an attribute or a placed class and press Delete to hide it from the diagram. This is a view action, not model deletion.
| Action | Result |
|---|---|
Delete on a placed class or visible feature
|
Hides it from the current diagram; it remains in the repository and model. |
Ctrl+Delete
|
Deletes the selected model element. |
Gotcha: Use Ctrl+Delete only when you intend to remove the model element. If you only want a cleaner diagram, use Delete or Pick show featuresâŚ.
If you have removed an association from the diagram view, right-click and use Introduce and remove, then Re-introduce removed associations to show it again.
Use color to communicate the diagram's purpose
You can assign color to a class representation on the current diagram, or set a default color on the class itself.
- A color set on the placed class applies to that placement on the diagram.
- A default color set on the class is used where no placement-specific color overrides it.
For example, set the placed House to blue on a lifecycle diagram to draw attention to it, while retaining a gold default color for the class elsewhere. Clear the placement-specific color to return to the class default.
Select a class, attribute, or association to view its properties in the Object Inspector. You can select several elements and move them together to improve the layout.
MDriven Designer also provides an automatically generated graphical display of a class, its attributes, and relations. This view is useful for navigation because it exposes the available elements rather than applying the selective presentation of a manually arranged diagram. See Documentation:Autodiagram for the distinction and use of autogenerated diagrams.
You can also place one diagram inside another diagram as a thumbnail. Double-click the placed diagram to navigate into it. MDriven limits recursive diagram display to two levels. See Documentation:Diagrams in Diagrams for this navigation and organization technique.
Use class diagrams with other diagram types
Class diagrams describe the structural domain model. Use a state diagram when you need to describe the states and transitions of a class. For example, a House can have a state attribute and a state diagram that describes its lifecycle, while the class diagram shows how House relates to Street.
When you execute a model with Turnkey, the types available for attributes are the types available for the executing model. Keep attributes typed and express relationships to other model classes as associations.
