Tutorial 1: A Basic Class Diagram Language
In this tutorial you will build a simple UML class diagram language from scratch. By the end, you will have a working language workbench that lets you create class diagrams with classes, attributes, and associations.
Prerequisites: A Jjodel account and familiarity with the Getting Started guide.
Time: ~20 minutes
Part 1 — The Metamodel
Section titled “Part 1 — The Metamodel”The metamodel defines what elements exist in your language and how they relate to each other.
Step 1.1 — Create the Project
Section titled “Step 1.1 — Create the Project”- Log in to app.jjodel.io
- From the Dashboard, create a New Project named
UMLClassDiagram
Step 1.2 — Define the ClassDiagram Root Class
Section titled “Step 1.2 — Define the ClassDiagram Root Class”- Open the Metamodel Editor
- Create a new class called
ClassDiagram- Set isRootable to
true— this class will be the root container of every model
- Set isRootable to
- This class will contain all other elements
Step 1.3 — Define the Class Element
Section titled “Step 1.3 — Define the Class Element”- Create a new class called
Class - Add the following attributes:
name: StringisAbstract: Boolean(default:false)
- Create a containment reference from
ClassDiagramtoClass- Name:
classes - Multiplicity:
0..*
- Name:
Step 1.4 — Define Attribute
Section titled “Step 1.4 — Define Attribute”- Create a new class called
Attribute - Add attributes:
name: Stringtype: Stringvisibility: String(values:public,private,protected)
- Create a containment reference from
ClasstoAttribute- Name:
attributes - Multiplicity:
0..*
- Name:
Step 1.5 — Define Association
Section titled “Step 1.5 — Define Association”- Create a new class called
Association - Add attributes:
name: StringsourceMultiplicity: StringtargetMultiplicity: String
- Create two non-containment references:
source→Class(multiplicity:1..1)target→Class(multiplicity:1..1)
- Create a containment reference from
ClassDiagramtoAssociation- Name:
associations - Multiplicity:
0..*
- Name:
Step 1.6 — Add Inheritance
Section titled “Step 1.6 — Add Inheritance”- Create a class called
Inheritance - Create two non-containment references:
parent→Class(multiplicity:1..1)child→Class(multiplicity:1..1)
- Add a containment reference from
ClassDiagramtoInheritance- Name:
inheritances - Multiplicity:
0..*
- Name:
Your metamodel is complete. It defines a language with class diagrams containing classes (with attributes), associations, and inheritance relationships.
Part 2 — The Model
Section titled “Part 2 — The Model”Now create a sample model using the language you just defined.
Step 2.1 — Create a New Model
Section titled “Step 2.1 — Create a New Model”- From the workspace, create a New Model conforming to your
UMLClassDiagrammetamodel - Create a
ClassDiagramroot instance
Step 2.2 — Add Classes
Section titled “Step 2.2 — Add Classes”Create the following classes:
Person
name: Stringage: Integeremail: String
Student (extends Person)
studentId: StringenrollmentYear: Integer
Course
title: Stringcredits: Integer
Step 2.3 — Add Relationships
Section titled “Step 2.3 — Add Relationships”-
Create an Association named
enrolledIn- Source:
Student - Target:
Course - Source multiplicity:
0..* - Target multiplicity:
1..*
- Source:
-
Create an Inheritance
- Parent:
Person - Child:
Student
- Parent:
Part 3 — The Viewpoint
Section titled “Part 3 — The Viewpoint”Finally, create a visual viewpoint to render your model as a UML class diagram.
Step 3.1 — Create a Viewpoint
Section titled “Step 3.1 — Create a Viewpoint”- Open the Viewpoint Editor
- Create a new viewpoint named
ClassDiagramNotation
Step 3.2 — Define the Class View
Section titled “Step 3.2 — Define the Class View”Create a view for the Class metaclass:
- Shape: Rectangle
- Header: Display
self.namein bold - Compartment: List
self.attributesasname: typeentries - Style: White fill, black border, if
self.isAbstractthen italic name
Step 3.3 — Define the Association View
Section titled “Step 3.3 — Define the Association View”Create a view for Association:
- Shape: Edge (line connecting source and target)
- Label: Display
self.nameat the midpoint - Source label:
self.sourceMultiplicity - Target label:
self.targetMultiplicity
Step 3.4 — Define the Inheritance View
Section titled “Step 3.4 — Define the Inheritance View”Create a view for Inheritance:
- Shape: Edge with a hollow triangle arrowhead at the parent end
- Line style: Solid
Step 3.5 — Apply and Enjoy
Section titled “Step 3.5 — Apply and Enjoy”Apply the viewpoint to your model. You should see a proper UML class diagram with Person, Student, and Course rendered as boxes, connected by association lines and an inheritance arrow.
What You Learned
Section titled “What You Learned”In this tutorial you:
- Defined a complete metamodel for a class diagram language
- Created a model instance with classes, attributes, and relationships
- Built a visual viewpoint that renders the model as a UML class diagram
- Experienced Jjodel’s live co-evolution — changes to the metamodel were immediately reflected in the model and viewpoint
Next Steps
Section titled “Next Steps”- Tutorial 2: Custom Viewpoints — explore advanced viewpoint features
- Viewpoints Reference — deep dive into viewpoint configuration
- Anatomy of a Modeling Language — understand the theoretical foundations