list of dots Digital Research Alliance of Canada logo  NSERC logo  University of Ottawa logo / UniversitĂ© d'Ottawa

User Manual    [Previous]   [Next]   

Class Definition

A class definition defines an object-oriented class available for use as a type in the system you are developing. Objects (chunks of data) are created as instances of the class. A class describes the structure of that data in terms of attributes (simple data like strings and numbers), associations (links to and from other objects), state machines, as well as many other things described in this manual.

To define a class in Umple, specify the keyword 'class', followed by the name of the class (starting in a capital letter in order to respect naming conventions as well as to avoid a warning) and then the body of the class within curly brackets.

The body can contain various elements that are listed in the Class Content page.

Traits can be used to add the same set of items to several unrelated classes..

The following UML diagram shows two classes: a Student class and an Address class, linked by an association. The corresponding Umple is below.

UML diagram showing Student and Address

Example Showing two Classes (Class Diagram is Above)


class Student
{
  firstName;   // attribute - defaults to String
  lastName;
  Integer number;  // attribute with type Integer
  * -- * Address;  // Many-to-many association
  
  // Method, whose content is not processed by Umple
  public String fullName()  
  {
    return getFirstName() + " " + getLastName();
  } 
}

class Address
{
  String[] line;  // Multi-valued attribute
}
      

Load the above code into UmpleOnline

 

YouTube Video with Additional Explanation

 
 

Syntax


// Classes are the most common elements in Umple.
// See user manual page ClassDefinition
classDefinition : class [name] { [[classContent]]* }

// The following items can be found inside the body of classes or association classes
classContent- : [[comment]]
    | [[reqImplementation]]
    | [[innerClass]]
    | [[mixsetDefinition]]
    | [[distributable]]
    | [[proxyPattern]]
    | [[strictness]]
    | [[classDefinition]]
    | [[trace]]
    | [[emitMethod]]
    | [[templateAttributeDefinition]]
    | [[primitiveDefinition]]
    | [[portDefinition]]
    | [[portBindingDefinition]]
    | [[position]]
    | [[displayColor]]
    | [[abstract]]
    | [[keyDefinition]]
    | [[softwarePattern]]
    | [[depend]]
    | [[symmetricReflexiveAssociation]]
    | [[attribute]]
    | [[testCase]]
    | [[genericTestCase]]
    | [[testSequence]]
    | [[testClassInit]]
    | [[stateMachine]]
    | [[activeMethodDefinition]]
    | [[inlineAssociation]]
    | [[concreteMethodDeclaration]]
    | [[constantDeclaration]]
    | [[modelConstraint]]
    | [[invariant]]
    | ;
    | [[enumerationDefinition]]
    | [[exception]]
    | [[extraCode]]