Mixsets with Traits
[Previous]  [Next] 
|
User Manual [Previous]  [Next] Mixsets with TraitsTraits 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. Exampletrait 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 SyntaxtraitDefinition : 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]]  ) |