300 likes | 325 Views
This paper discusses the philosophy of Model-Oriented Programming and explores Umple, a MOP technology and language family that supports modeling abstractions and integrates with various programming languages and tools.
E N D
SERA 2013 (August 7, 2013 in Prague, Czech Republic) Omar Badreddin, Andrew Forward, Timothy C. Lethbridge1 University of Ottawa obadr024@uottawa.ca / oobahy@gmail.com aforward@site.uottawa.ca / aforward@gmail.com tcl@site.uottawa.ca http://umple.org Exploring a Model-Oriented and Executable Syntax for UML Attributes
Overview • Model Oriented Programming • Umple Overview • Attributes in Practice • Umple Attribute Syntax • Attribute Code Generation
MOP The philosophy of Model-Oriented Programming (MOP)
Supports Modellerand Programmer workflows Model-First Incremental Re-Engineering
Umple A MOP technology and language family
Why call it Umple? UML Programming Language Ample Simple
What does Umple support? • Modeling abstractions • Associations, Attributes, State machines (both simple and composite), model based tracing, and simple debugging. • Supported languages • Java, C++, Ruby, PhP • Integration support • XMI for model exchange, Ecore, textUML, Yuml, GraphViz, SQL
Attributes In Practice Google Code: • fizzbuzz • ExcelLibrary • Ndependencyinjection • Java Bug Reporting SourceForge: • jEdit • Freemaker Freecode: • Java Financial Library • 1831 variables • 620 static • 1211 instance • 469 classes
Variable Distribution Static (Class) Variables E.g. avoiding magic numbers and state symbols (i.e. LEFT_NODE, RIGHT_NODE) Member (Object) Variables Mostly counts, names and booleans(51%) A lot of other object types
Attribute Identification About 33% had attribute-like methods implementations Surprising that 35% had no external access at all
Attribute Code Generation Over half were simple boiler-plate implementations
Observations • Many simple set and get methods • Drastic reduction in boiler-plate code • Few trulyimmutable attributes • Few attributes set in constructor • Immutability needed for proper hash code (Java) • Attribute multiplicities typically ‘one’ • Basic multiplicity (0..1, 1, 0..*) available for attributes
Umple Attributes class Student { // defaults to String studentNumber; String grade; IntegerentryAverage; }
Umple Data Types Umple treats the following attribute types as special String (always the default if unspecified) Integer Double Boolean Date, Time • Code generation from the above will generate suitable types in the underlying language (Java, PHP, etc.) • Umple classes can be used as types, but consider associations instead
Initializing Attributes class Student { // Initial value set to “Unknown”, // not required in class constructor name = "Unknown"; // Initialized, but can also be reset defaulted type = “FullTime”; // Name initialized to null in // constructor lazy program; }
Immutable Attributes class Student { // Cannot be changed after set in constructor immutableidNumber; // Can be set once, right after construction, // and is immutable after that // Useful for frameworks where objects are // created without initializing values lazy immutable barcode; }
Derived Attributes class Rectangle { Integer l; Integer w; // Derived Attributes Integer perimeter = { 2*getL() + 2*getW() } Integer area = { getL() * getW() } }
Additional Attribute Options class Student { // Umple assigns the next // available number autouniqueid; // Creates a constant value constInteger MAX_NUM_COURSES = 8; } class Address { // An address has many lines String[] lines; }
Attribute Code Generation (1) class Rectangle { name = "Rectangle"; Integerlength; Integerwidth; Integerarea = {getLenth() * getWidth()} }
Attribute Code Generation (2) // line 2 "model.ump" public class Rectangle { @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) public @interface umplesourcefile{int[] line();String[] file();int[] javaline();int[] length();} //------------------------ // MEMBER VARIABLES //------------------------ //Rectangle Attributes private String name; private int length; private int width; //------------------------ // CONSTRUCTOR //------------------------ public Rectangle(intaLength, intaWidth) { name = "Rectangle"; length = aLength; width = aWidth; } //------------------------ // INTERFACE //------------------------ public booleansetName(String aName) { booleanwasSet = false; name = aName; wasSet = true; return wasSet; } public booleansetLength(intaLength) { booleanwasSet = false; length = aLength; wasSet = true; return wasSet; } public booleansetWidth(intaWidth) { booleanwasSet = false; width = aWidth; wasSet = true; return wasSet; } public String getName() { return name; } public intgetLength() { return length; } public intgetWidth() { return width; } @umplesourcefile(line={7},file={"model.ump"},javaline={79},length={2}) public intgetArea() { return getLenth() * getWidth(); } public void delete() {} public String toString() { String outputString = ""; return super.toString() + "["+ "name" + ":" + getName()+ "," + "length" + ":" + getLength()+ "," + "width" + ":" + getWidth()+ "," + "area" + ":" + getArea()+ "]" + outputString; } } Simple get method Constructor based on attributes missing an initial value Set method returns a boolean (was it “set” or not) Derived methods do not have internal members
Try It Yourself http://try.umple.org
Summary Umple extends a base language in a minimally invasive way Umple features can be created and viewed diagrammatically or textually = Modeling is programming and vice versa Intermediate generated code should not be edited No round-trip engineering required
Getting involved • Open source project: https://code.google.com/p/umple/ • Teaching • Use Umple to introduce UML and MDE. • Umplification • Incrementally replace boilerplate code with modeling abstractions • Lightweight Modeling and Analysis • Visualize Umple source as UML diagrams to analyze it • Model driven development • Generate code in one of the supported base languages Comments and feedback: tcl@site.uottawa.ca
More information • Publications on Umple: https://code.google.com/p/umple/wiki/Publications • The User Manual: http://cruise.eecs.uottawa.ca/umple/GettingStarted.html • Umple Home page: http://cruise.eecs.uottawa.ca/umple/ • Download Umple: http://cruise.eecs.uottawa.ca/umpleonline/download_eclipse_umple_plugin.html • Report an issue: https://code.google.com/p/umple/issues/entry