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

User Manual    [Previous]   [Next]   

interface Definition

An interface defines a list of abstract methods that are to be implemented in one or more classes. An interface can be composed of the following elements:

To implement an interface in a class, or to create subinterfaces, use an isA clause.

Umple also supports a feature called traits, that has some similarities to interfaces. However, traits concrete methods, attributes and state machines to also be contained in them.

In the following example, RegisterCapable is an interface that defines a single abstract method registerForCourse(). This is implemented concretely by CorporateClient and IndividualStudent.


interface RegisterCapable
  depend school.util.*;
  boolean registerForCourse(Course aCourse);

class Person {

class CorporateClient {
  isA RegisterCapable;
  boolean registerForCourse(Course aCourse) {
     // write code here
  0..1 <- * Person employees;

class IndividualStudent {
  isA Person, RegisterCapable;
  boolean registerForCourse(Course aCourse) {
     // write code here

class Course
  * -- * Person registrants;

Load the above code into UmpleOnline



// An Interface can only contain method. See interfaceDefinition
interfaceDefinition : interface [name] { [[depend]]* [[interfaceBody]] }

// Interfaces: Note that if the format of an abstractMethodDeclaration is not
// followed, then the body will extraCode and passed to the base language
// See user manual page interfaceDefinition
interfaceBody- : [[interfaceMemberDeclaration]]*

interfaceMemberDeclaration : [[comment]]
    | [[reqImplementation]]
    | [[constantDeclaration]]
    | [[constantDeclarationDeprecated]]
    | [[abstractMethodDeclaration]]
    | [[position]]
    | [[displayColor]]
    | [[isA]]
    | [[interfaceTest]]
    | [[distributableInterface]]
    | [[exception]]
    | [[extraCode]]