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

User Manual    [Previous]   [Next]   

Mixsets with Traits

Traits can include mixsets with their bodies. For example, the code below contains the 'Numerical' mixset, which ensures the implementaion of extra methods (isGreaterThan and isLessThan) when its activited by a use statement.

Example

trait TEquality{
  Boolean isEqual(Object object);
  Boolean isNotEqual(Object object) Java {
    
    return isEqual(object) ? false : true;
  }
  
  mixset Numerical {
    Boolean isGreaterThan(Object object);
    Boolean isLessThan(Object object);
  }
}

class RealNumber 
{
  float value;  
  isA TEquality;

  Boolean isEqual (Object object)Java
  {
    if(object instanceof RealNumber)
    return this.value == ((RealNumber) object).value;
    else
    return false;
  }
}

/* 
   The below use statement generates an error in Umple when its activited.
   Because the trait TEquality has the Numerical mixset, and there is no 
   implementaion for its methods (isGreaterThan and isLessThan).
 */             
//use Numerical; 



      

Load the above code into UmpleOnline

 

Syntax


traitDefinition : trait [name] [[traitParameters]]? { [[traitContent]]* }

traitContent- : [[mixsetDefinition]]
    | [[testCase]]
    | [[requiredModelElements]]
    | [[comment]]
    | [[reqImplementation]]
    | [[traitDefinition]]
    | [[trace]]
    | [[position]]
    | [[displayColor]]
    | [[abstract]]
    | [[keyDefinition]]
    | [[softwarePattern]]
    | [[depend]]
    | [[symmetricReflexiveAssociation]]
    | [[attribute]]
    | [[stateMachine]]
    | [[inlineAssociation]]
    | [[concreteMethodDeclaration]]
    | [[abstractMethodDeclaration]]
    | [[constantDeclaration]]
    | [[invariant]]
    | ;
    | [[exception]]
    | [[extraCode]]

mixsetDefinition : mixset [mixsetName]
  ( [[mixsetInnerContent]]
    | [[requirement]]
    | [[mixsetInlineDefinition]]
  )