This tutorial introduces a small MDriven Designer workflow: create a model, add a class and attribute, run it with XML persistence, create data, save it, and query it with OCL.
Before you begin
Follow the installation instructions linked from Bootcamp Chapter 1, then start MDriven Designer.
Build a Person model
- Create a new empty model.
- Save the model on your device. For example, save it as
c:\temp\MDrivenEducation\Start.modlr, or use an equivalent location. - Create a class named
Person. - Add an attribute named
Namewith typeStringto thePersonclass. - Save the model. Continue saving with
CTRL + Sas you work.
Your model has one class and one attribute:
| Class | Attribute | Type |
|---|---|---|
Person
|
Name
|
String
|
Run the model and create data
- Press the Play button on the left of the top menu.
- Choose XML persistence.
- Select Start system, then select Show debugger.
- In a Debugger Expression box, enter and run this OCL expression:
person.allinstances
- Confirm that the result list is empty. You have defined the
Personclass, but have not yet created any Person objects. - In the Debugger, open a Seeker. Its search is empty.
- Select Create New twice to create two Person objects.
- Select the first row, right-click it, and select Open. In the AutoForm, enter your name in the
Namefield. - Open the second row and enter another name, such as
SomeOtherDude. - Use the save button in the Debugger to save the Person objects.
Verify the saved result
- Find the saved XML file on disk in the same location as the model file.
- Open the XML file in Notepad or another application, find the names you entered, and close the file.
- Return to the Debugger Expression box and run the expression again:
person.allinstances
- Confirm that the result contains two rows.
You have created a class and attribute in a model, run the model, created and saved objects, and queried the objects with OCL.
Next exercise: model a task planner
For an example that adds classes, associations, attributes, and derived values, see How to Build a Team Task Planner in 15 Minutes with MDriven. Its example uses Team, Project, Task, and Member classes, and introduces derived attributes defined with OCL.
