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

User Manual    [Previous]   [Next]   

Method Definition

The Umple language allows a developer to extend the functionality of a class with arbitrary methods written in the natively compiled language (e.g. Java, Php or Ruby).

Within these arbitrary methods, a developer may call generated methods that access the Umple attributes, associations and state machines. To determine what API methods are available to be called by methods, refer to the API reference or generate Javadoc from an Umple file using UmpleOnline.

A standard Umple method will specify the return type, then the name, then the argument list and finally the method body in curly brackets. The generated output for the method will use correct format for the generated language and will be public.

Example of a method with no arguments

generate Java;

// A class with a method displayName() that has no arguments
class Person
{
  name;
  
  String displayName()
  {
    return("Hello, my name is " + getName());
  }
}
      

Load the above code into UmpleOnline

 

Example of a method with arguments

generate Java;

// A class with a method that has arguments
class Person
{
  name;
  
  String displayName(String greeting, String property)
  {
    return(
      greeting +
      ", my " +
      property +
      " is " +
      getName());
  }
}

      

Load the above code into UmpleOnline

 

Example of a public method

generate Java;

// A class with a method that uses 'public'.
class Person
{
  name;
  
  public String displayName()
  {
    return("Hello, my name is " + getName());
  }
}
      

Load the above code into UmpleOnline

 

Syntax


// Methods: The code in concrete methods is passed to the base language
// See user manual page MethodDefinition
concreteMethodDeclaration : [=modifier:public|protected|private]? [=static]? [=synchronized]? [=queued]? [type]? [[methodDeclarator]] [[methodThrowsExceptions]]? [[methodBody]]
    | [=modifier:public|protected]? [=abstract] [type]? [[methodDeclarator]] [[methodThrowsExceptions]]? ;

methodDeclarator : [methodName] [[parameterList]]

parameterList : (
  ([[parameter]]
  ( , [[parameter]]
  )*
  )? )

parameter : [[typedName]]