CEN206 Object-Oriented Programming

CEN206 Object-Oriented Programming

Week-6 (UMPLE - Part 1)

Spring Semester, 2025-2026

Download DOC-PDF, DOC-DOCX, SLIDE

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Module A: Introduction to UMPLE

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Module Outline

  • What is UMPLE?
  • UMPLE Motivation and Key Innovations
  • Model-Driven Development with UMPLE
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Introduction to UMPLE

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE: Si&mple&, A&mple&, &UM&L &P&rogramming &L&anguag&e&

  • Open source textual modelling tool set for 3 platforms

    • Command line compiler

    • Web-based tool (UMPLEOnline) for demos and education

    • Eclipse plugin

  • Code generator for UML ++

    • Infinitely nested state machines, with concurrency

    • Proper referential integrity and multiplicity constraints on associations

    • Traits, mixins, aspects for modularity

    • Text generation templates, patterns, traits

  • Pre-processor to add UML, patterns and other features on top of
    Java, PhP, C++ and other languages

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE: Si&mple&, A&mple&, &UM&L &P&rogramming &L&anguag&e&

  • Open source textual modeling tool and code generator
    • Adds modeling to Java,. C++, PHP
    • A sample of features
      • Referential integrity on associations
      • Code generation for patterns
      • Blending of conventional code with models
      • Infinitely nested state machines, with concurrency
      • Separation of concerns for models: mixins, traits, mixsets, aspects
  • Tools
    • Command line compiler
    • Web-based tool (UMPLEOnline) for demos and education
    • Plugins for Eclipse and other tools
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

What Are we Going to Learn About in This Tutorial? What Will You Be Able To Do?

  • Modeling using class diagrams
    • Attributes, Associations, Methods, Patterns, Constraints
  • Modeling using state diagrams
    • States, Events, Transitions, Guards, Nesting, Actions, Activities
    • Concurrency
  • Separation of Concerns in Models
    • Mixins, Traits, Aspects, Mixsets
  • Practice with a examples focusing on state machines and product lines
  • Building a complete system in UMPLE
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

What Technology Will You Need?

  • As a minimum: Any web browser.
  • For a richer command-line experience
    • A computer (laptop) with Java 8-14 JDK
    • Mac and Linux are the easiest platforms, but Windows also will work
    • Download UMPLE Jar at http://dl.UMPLE.org
  • You can also run UMPLE in Docker: http://docker.UMPLE.org
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Key Websites

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Key Websites (Another way)

The UMPLEOnline web interface is at try.UMPLE.org

The user manual is at manual.UMPLE.org

The UMPLE home page is at www.UMPLE.org

UMPLE download page: dl.UMPLE.org

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Motivation for developing UMPLE

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Motivation for developing UMPLE (1)

Designers want the best combination of features:

  • Textual editing and blending with other languages

  • Ability to use in an agile process

    • Write tests, continuous integration, versioning

    • Combine the best of agility and modeling

  • Excellent code generation

    • A complete generation of real systems (including itself)
  • Multi-platform (command line, Eclipse, VsCode, Web)

  • Practical and easy to use for developers

    • Including great documentation
  • Open source

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Motivation for developing UMPLE (2)

Many existing tools:

  • Lacked in usability

    • Awkward to edit diagrams

    • Many steps to do a task

    • Lengthy learning process

  • Lack in ongoing support

  • Could be enhanced by us perhaps, but we would be tied to key decisions (e.g. Eclipse-only)

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Takeaway: Introduction to UMPLE

  • UMPLE = UML + Programming Language - adds UML constructs directly into code
  • Model-driven development: write models that generate production-quality code
  • UMPLE supports Java, C++, PHP, Ruby code generation from UML models
  • Key innovation: seamless integration of modeling and programming
  • UMPLE eliminates the gap between design models and implementation
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Module B: Using UMPLE & Philosophy

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Module Outline

  • UMPLE Key Innovations
  • Using UMPLE (Online, Command-Line, Eclipse, VS Code)
  • UMPLE Philosophy
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Some key UMPLE innovations

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Some key UMPLE innovations

  • Model is code

    • Traditional code is embedded in model
  • No need to edit generated code

    • No round-trip engineering
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Using UMPLE

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Using UMPLE

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Docker Container Experimental

mkdir ~/src && cd ~/src &&  git clone git@github.com:UMPLE/UMPLE.git
docker run -i -t -v `pwd`:/src UMPLE/UMPLE:0.4.0 bash
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Using UMPLE

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE Philosophy

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE Philosophy 1-4

  • P1. Modeling is programming and vice versa

  • P2. An UMPLE programmer should never need to edit generated code to accomplish any task.

  • P3. The UMPLE compiler can accept and generate code that uses nothing but UML abstractions.

    • The above is the inverse of the following
  • P4. A program without UMPLE features can be compiled by an UMPLE compiler.

    • e.g. input Java results in the same as output
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE Philosophy 5-8

  • P5. A programmer can incrementally add UMPLE features to an existing program

    • Umplification
  • P6. UMPLE extends the base language in a minimally invasive and safe way.

  • P7. UMPLE features can be created and viewed diagrammatically or textually

  • P8. UMPLE goes beyond UML

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Takeaway: Using UMPLE & Philosophy

  • UMPLE can be used online (try.umple.org), via command line, or through IDE plugins
  • Philosophy: modeling should be part of programming, not a separate activity
  • UMPLE treats UML associations, state machines, and patterns as first-class language constructs
  • Code generation produces clean, readable code in target languages
  • UMPLE is open-source and actively maintained
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Module C: UMPLE Class Modeling & Attributes

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Module Outline

  • UMPLE Class Modeling Basics
  • Defining Classes and Namespaces
  • UMPLE Attributes (Basic, Defaulted, Derived, Immutable, Lazy, Autounique)
  • Attribute Types and Constraints
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE Class Modeling

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE Class Models - Quick Overview

  • Key elements:

    • Classes

    • Attributes

    • Associations

    • Generalizations

    • Methods

  • We will look at all these using examples via UMPLE ONLINE

  • UMPLE code/models are stored in files with suffix .ump

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Exercise: Compiling and changing a model

  • Look at the example at the bottom of

  • Click on Load the above code into UMPLEOnline

    • Observe and modify the diagram
    • Add an attribute
    • Make a multiplicity error, then undo
    • Generate code and take a look
    • Download, compile and run if you want
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Hello World Example 2 in the User Manual

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Key tools:

  • UMPLE Online
  • Command-Line
  • User Manual
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Hello World example 2 in UMPLEOnline

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Exploration of UMPLEOnline

  • Explore class diagram examples
  • Options
    • T or Control-t (hide and show text)
    • D or Control-d (hide and show diagram)
    • A, M to hide and show attributes, methods
    • Default diagram types
      • G/Control-g (Graphviz), S/Control-s (State Diagram)
      • E/Control-e (Editable class diagram)
  • Generate code and look at the results
    • In UMPLE you never should modify generated code
    • It is designed to be readable for educational purposes
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Use of the UMPLEOnline Docker image

  • UMPLE's server can handle 80,000 transactions per hour

    • Code generations, edits
  • But needs a good Internet connection
    (sometimes hundreds of students have assignments due)

  • To maximize speed of UMPLEOnline run it in your local machine:

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Demo of compiling on the command line

  • To compile on the command line you will need Java 8
  • Download UMPLE from http://dl.UMPLE.org
  • Basic compilation
java -jar UMPLE.jar model.ump
  • Help for features and commands
java -jar UMPLE.jar --help
  • To generate and compile the java to a final system
java –jar UMPLE.jar model.ump -c -
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Quick walkthrough of the user manual

Note in particular

  • Key sections:
    • attributes,
    • associations,
    • state machines
  • Grammar
  • Generated API
  • Errors and warnings
  • Editing pages in github
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE Attributes

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Attributes

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Attributes Exercise #1

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Attributes

  • "Instance variables"

    • Part of the state of an object
    • Simple data that will always be present in each instance
  • Specified like a Java or C++ field or member variable

  • But, intended to be more abstract!

    • Example, with an initial value
a = "init value";
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Attributes

  • As in UML, more abstract than instance variables

    • Always private by default

    • Should only be accessed get, set methods

    • Can be stereotyped (upcoming slides) to affect code generation

    • Can have aspects applied (discussed later)

    • Can be constrained (discussed later)

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Code generation from attributes

  • Default code generation
    • Generates a getName() and setName() method for name
      • public
  • Creates an arguments in the class constructor by default
  • An attribute is private to the class by default
    • Should only be accessed get, set methods
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Code Generation (JavaDocs)

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Code Generation Patterns

  • Attributes

    • Set/Get (UB = 1)
    • Add/Remove/NumberOf/IndexOf/Get (UB > 1)
    • Lazy immutability
    • Default values
    • Constants
    • Before / After cod

    UB = upper bound

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Code Generation Patterns

  • Associations

    • Set/Get (UB = 1)
    • Add/Remove/NumberOf/IndexOf/Get (UB > 1)
    • Referential Integrity
    • Multiplicity Constraints
    • 42 different cases

    UB = upper bound

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Code Generation (Semantics)

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE builtin datatypes

String // (default if none specified)
Integer
Float
Double
Boolean
Time
Date
  • The above will generate appropriate code in Java, C++ etc.
    • e.g. Integer becomes int
  • Other (native) types can be used but without guaranteed correctness
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Attribute stereotypes (1)

  • Code generation can be controlled through stereotypes:
    • lazy - don't add a constructor argument
lazy b; // sets it to null, 0, "" depending on type
  • Defaulted – can be reset
defaulted s = "def"; // resettable to the default
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Attribute stereotypes (2)

  • autounique – provide a unique value to each instance
autounique x; // sets attribute to 1, 2, 3 ...
  • internal – don't generate any methods
internal i; // doesn't generate any get/set either
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Immutability

  • Useful for objects where you want to guarantee no possible change once created

    • e.g. a geometric point
  • Generate a constructor argument and get method but no set method

immutable String str;
  • No constructor argument, but allows setting just once.
lazy immutable z;
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Lets explore attributes by example

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Derived attributes

  • These generate a get method that is calculated.
class Point
{
// Cartesian coordinates
Float x;
Float y;

// Polar coordinates
Float rho =
{Math.sqrt(Math.pow(getX(), 2) + Math.pow(getY(), 2))}
Float theta =
{Math.toDegrees(Math.atan2(getY(),getX()))}

}
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Multi-valued attributes

  • Limit their use. Associations are generally better.
class Office {
Integer number;
Phone[] installedTelephones;
}

class Phone {
String digits;
String callerID;
}
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Keys

  • Enable UMPLE to generate an equals() and a hashcode() method
class Student {
Integer id;
name;
key { id }
}
  • The user manual has a sports team example showing keys on associations too
  • Note how this feature is not inherited from UML
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Takeaway: UMPLE Class Modeling & Attributes

  • UMPLE classes look like simplified Java/C++ with UML-level abstractions
  • Attribute types: basic, defaulted (with initial value), derived (computed), immutable (set once)
  • Lazy attributes: initialized only when first accessed
  • Autounique attributes: automatically assigned unique integer values
  • UMPLE generates complete getter/setter methods and constructor logic from attribute declarations
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Module D: Generalization, Methods & Associations

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Module Outline

  • UMPLE Generalization and Interfaces
  • UMPLE Methods
  • UMPLE Associations (Types, Multiplicity, Reflexive, Sorted, Qualifiers)
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE Generalization and interfaces

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Generalization in UMPLE

  • UMPLE uses the isA keyword to indicate generalization
  • Used to indicate superclass, used trait, implemented interface
class Shape {
colour;
}
class Rectangle {
isA Shape;
}
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Avoiding unnecessary generalizations

Open in UMPLE

  • Inappropriate hierarchy of Classes

  • What should the model be?

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Interfaces

  • Declare signatures of a group of methods that must be implemented by various classes

  • Also declared using the keyword isA

  • Essentially the same concept as in Java

  • Let's explore examples in the user manual …

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE Methods

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

User-written Methods in UMPLE

  • Methods can be added to any UMPLE code.

  • UMPLE parses the signature only; the rest is passed to the generated code.

  • You can specify different bodies in different languages

  • We will look at examples in the user manual …

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

UMPLE Associations

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Associations

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Associations Exercise #1

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Associations Exercise #2

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Associations

  • Describe how instances of classes are linked at runtime
    • Bidirectional -- or
    • Unidirectional ->
  • Multiplicity:
    • Bounds on the number of linked instances
  • * Or 0..* \longrightarrow 0 or more
  • 1..* \longrightarrow 1 or more
  • 1 \longrightarrow Exactly 1
  • 2 \longrightarrow Exactly 2
  • 1..3 \longrightarrow Between 1 and 3
  • 0..2 \longrightarrow Up to 2
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Association Relationships

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Association Relationships

  • Directional Associations
* -> 0..1, * -> 1, * -> *, * -> m..n, * - >n, *->m..* and*->0..n.
  • Symmetric Reflexive
0..1, 0..n, *, 1, n, m..n,m..*
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Basic UML associations

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Many-to-one associations (1)

class Employee {
id;
firstName;
lastName;
}

class Company {
name;
1 -- * Employee;
}
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Many-to-one associations (2)

  • A company has many employees,
  • An employee can only work for one company.
    • This company will not store data about the moonlighting activities of employees!
  • A company can have zero employees
    • E.g. a 'shell' company
  • It is not possible to be an employee unless you work for a company
  • Let's draw and write this in UMPLEOnline:

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Role names (optional, in most cases)

  • Allow you to better label either end of an association
class Person{
id;
firstName;
lastName;
}

class Company {
name;
1 employer -- * Person employee;
}
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Referential Integrity

  • When an instance on one side of the association changes

    • The linked instances on the other side know …

    • And vice-versa

  • This is standard in UMPLE associations, which are
    bidirectional

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Many-to-Many Associations

  • An assistant can work for many managers
  • A manager can have many assistants
  • Assistants can work in pools working for several managers
  • Managers can have a group of assistants
  • Some managers might have zero assistants.
  • Is it possible for an assistant to have, perhaps temporarily, zero managers?

Open in UMPLE

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

One-to-One Associations (Use cautiously)

  • For each company, there is exactly one board of directors
  • A board is the board of only one company
  • A company must always have a board
  • A board must always be of some company

Open in UMPLE

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Typical erroneous use of one-to-one

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Unidirectional Associations

  • Associations are by default bi-directional
  • It is possible to limit the direction of an association by adding an arrow at one end
  • In the following unidirectional association
    • A Day knows about its notes, but a Note does not know which Day is belongs to
    • Note remains 'uncoupled' and can be used in other contexts
class Day {
* -> 1 Note;
}
class Note {}

Open in UMPLE

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Association Classes

  • Sometimes, an attribute that concerns two associated classes cannot be placed in either of the classes

Open in UMPLE

and Extended Example

center

  • The following are nearly equivalent
    • The only difference:
      • in the association class there can be only a single registration of a given Student in a CourseSection

center

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Association classes (cont.)

  • UMPLE code
class Student {}
class CourseSection {}
associationClass Registration {
*  Student;
*  CourseSection;
}
  • Open in UMPLEOnline, and then generate code
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Reflexive Associations

  • An association that connects a class to itself

center

Open in UMPLE

class Course {
* self isMutuallyExclusiveWith; // Symmetric
}

association {
* Course successor -- * Course prerequisite;
} 
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Inline vs. Standalone associations

  • The following are equivalent to allow flexibility:
class X {}
class Y {
1 -- * X;

}
class X {}
class Y {}
association {
1 Y -- * X;

}
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Aggregation

  • Aggregations are ordinary associations that represent part-whole relationships.
    • The 'whole' side is often called the assembly or the aggregate
    • This is a shorthand for association named isPartOf
    • UMPLE has no special syntax currently

center

class Vehicle {
1 whole -- * VehiclePart part;
}
class VehiclePart{
}
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Composition

  • A composition is a strong kind of aggregation
    • If the aggregate is destroyed, then the parts are destroyed as well

class Building {
1 <@>- * Room;
}
class Room{
}
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Sorted Associations

  • Order objects in the association according to a specific key
class Academy {
1 -- * Student registrants sorted {id};
}

class Student {
Integer id;
name;
}
  • We will look at a more complete example in the User Manual
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

A final word on associations

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

Takeaway: Generalization, Methods & Associations

  • UMPLE supports inheritance (isA keyword) and interface implementation
  • Methods can be added directly in UMPLE alongside UML constructs
  • Associations define relationships between classes with multiplicity (, 0..1, 1.., etc.)
  • UMPLE generates referential integrity code for associations automatically
  • Special association features: reflexive, sorted, qualified associations
RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

References

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

References

RTEU CEN206 Week-6
CEN206 Object-Oriented Programming

EndOfWeek6End-Of-Week-6

RTEU CEN206 Week-6