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

User Manual    [Previous]   [Next]   

Alternative Languages

In Umple, the body of a method will by default be emitted unchanged. This ties the model to the particular programming language. However it is possible to provide alternative implementations for different programming languages by preceding the method body with the language name.

This multi-lingual capability also works for other places where native code is injected such as in state machine guards and actions, or in derived attributes.

Example

// Generating Java and Php the following will
// result in the appropriate 
// method body being selected.
class LanguageSpecific {
  int m1() Java {
    // Return 1 if the model is compiled into Java
    return 1;
  }
  Php {
     // Return 0 if the model is compiled into Php
    return 0;
  }
}
      

Load the above code into UmpleOnline

 

Another Example

// A method body may work for several languages.
// If no language is specified it is taken as the
// default.
class LanguageSpecific {
  int m1()
  Java,Php {
    // Return 0 if the model is compiled into
    // Java or Php
    return 0;
  }
  {
    // Default implementation for other languages
    return 1;
  }
}
      

Load the above code into UmpleOnline