Optional:
UMPLE in Eclipse
cmake and gcc for compiling C++ code
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.
P4. A program without UMPLE features can be compiled by an UMPLE compiler.
P5. A programmer can incrementally add UMPLE features to an existing program
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
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
Look at the example at the bottom of
Click on Load the above code into UMPLEOnline
T
or Control-t
(hide and show text)D
or Control-d
(hide and show diagram)A
, M
to hide and show attributes, methodsG
/Control-g
(Graphviz), S
/Control-s
(State Diagram)E
/Control-e
(Editable class diagram)UMPLE’s server can handle 80,000
transactions per hour
But needs a good Internet connection
(sometimes hundreds of students have assignments due)
To maximize speed of UMPLEOnline run it in your local machine:
java -jar UMPLE.jar model.ump
java -jar UMPLE.jar --help
java –jar UMPLE.jar model.ump -c -
Note in particular
"Instance variables"
Specified like a Java or C++ field or member variable
But, intended to be more abstract!
a = "init value";
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)
getName()
and setName()
method for name
public
private
to the class by default
Attributes
UB = upper bound
Associations
UB = upper bound
String // (default if none specified)
Integer
Float
Double
Boolean
Time
Date
lazy b; // sets it to null, 0, “” depending on type
defaulted s = "def"; // resettable to the default
autounique x; // sets attribute to 1, 2, 3 …
internal i; // doesn’t generate any get/set either
Useful for objects where you want to guarantee no possible change once created
Generate a constructor argument and get method but no set method
immutable String str;
lazy immutable z;
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()))}
}
class Office {
Integer number;
Phone[] installedTelephones;
}
class Phone {
String digits;
String callerID;
}
equals()
and a hashcode()
methodclass Student {
Integer id;
name;
key { id }
}
isA
keyword to indicate generalizationsuperclass
, used trait
, implemented interface
class Shape {
colour;
}
class Rectangle {
isA Shape;
}
Inappropriate hierarchy of Classes
What should the model be?
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 …
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 …
--
or->
*
Or 0..*
0 or more1..*
1 or more1
Exactly 12
Exactly 21..3
Between 1 and 30..2
Up to 2* -> 0..1, * -> 1, * -> *, * -> m..n, * - >n, *->m..* and*->0..n.
0..1, 0..n, *, 1, n, m..n,m..*
class Employee {
id;
firstName;
lastName;
}
class Company {
name;
1 -- * Employee;
}
class Person{
id;
firstName;
lastName;
}
class Company {
name;
1 employer -- * Person employee;
}
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
class Day {
* -> 1 Note;
}
class Note {}
and Extended Example
class Student {}
class CourseSection {}
associationClass Registration {
* Student;
* CourseSection;
}
class Course {
* self isMutuallyExclusiveWith; // Symmetric
}
association {
* Course successor -- * Course prerequisite;
}
class X {}
class Y {
1 -- * X;
}
class X {}
class Y {}
association {
1 Y -- * X;
}
isPartOf
class Vehicle {
1 whole -- * VehiclePart part;
}
class VehiclePart{
}
class Building {
1 <@>- * Room;
}
class Room{
}
class Academy {
1 -- * Student registrants sorted {id};
}
class Student {
Integer id;
name;
}