JavaScript is disabled so the dynamic features of this page will not work. To use UmpleOnline, turn Javascript on. Otherwise you can download the command-line Umple compiler or use Eclipse.
/*
* Introductory example of Umple showing classes,
* attribute, association, generalization, methods
* and the mixin capability.
* Generate either Python or Cpp and run this.
*
* The output will be:
* The mentor of Tom The Student is Nick The Mentor
* The students of Nick The Mentor are [Tom The Student]
*
* If you try to execute this with Java, it will
* indicate there is no Java main program. See
* the separate Java example in the user manual.
*/
class Person {
name; // Attribute, string by default
String __str__() Python {
return self.getName()
}
}
class Student {
isA Person;
}
class Mentor {
isA Person;
}
association {
0..1 Mentor -- * Student;
}
class Person {
// Notice that we are defining more contents for Person
// This uses Umple's mixin capability
public static void main(String [ ] args) Python{
import Mentor
import Student
m = Mentor.Mentor("Nick The Mentor")
s = Student.Student("Tom The Student")
s.setMentor(m)
print("The mentor of " + str(s) + " is " + str(s.getMentor()))
print("The students of " + str(m) + " are " + str(list(map(str, m.getStudents()))))
}
public static void main(String [ ] args) Cpp {
// Creating a mentor and a student.
Mentor m("Nick The Mentor");
Student s("Tom The Student");
// Associating the student with the mentor
s.setMentor(&m);
m.addStudent(&s);
// Retrieving and printing the mentor of the student.
cout << "The mentor of " << s.getName() << " is " << s.getMentor()->getName() << endl;
// Retrieving the list of students of the mentor.
vector* students = m.getStudents();
cout << "The students of " << m.getName() << " are: " << endl;
// Iterating over the students and printing their names.
for (Student* student : *students) {
cout << student->getName() << endl;
}
return 0;
}
}
//$?[End_of_model]$?
class Person
{
position 154 29 109 60;
}
class Mentor
{
position 253 130 109 45;
}
//$?[End_of_model]$?
// @@@skippythoncompile - quires Python 3, Current CLI uses Python 2.7