uOttawaUniversity of Ottawa - Canadas University
list of dots

Umple User Manual    [Previous]   [Next]   

Loading

Class Definition

A class definition defines an object-oriented class available for use as a type in your system.

To define a class, specify the keyword 'class', followed by the name of the class (starting in a capital letter) and then the body of the class within curly brackets. The body can contain various elements that are listed in the Class Content page.

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


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

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

Load the above code into UmpleOnline

 

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]]
    | [[distributable]]
    | [[proxyPattern]]
    | [[classDefinition]]
    | [[trace]]
    | [[emitMethod]]
    | [[templateAttributeDefinition]]
    | [[primitiveDefinition]]
    | [[portDefinition]]
    | [[portBindingDefinition]]
    | [[position]]
    | [[displayColor]]
    | [[abstract]]
    | [[keyDefinition]]
    | [[softwarePattern]]
    | [[depend]]
    | [[symmetricReflexiveAssociation]]
    | [[attribute]]
    | [[stateMachine]]
    | [[activeMethodDefinition]]
    | [[inlineAssociation]]
    | [[concreteMethodDeclaration]]
    | [[constantDeclaration]]
    | [[modelConstraint]]
    | [[invariant]]
    | ;
    | [[exception]]
    | [[extraCode]]