list of dots University of Ottawa logo / Université d'Ottawa

User Manual    [Previous]   [Next]   

Mixsets in Methods

Umple mixsets can be used to conditionally construct variant versions of methods that enable different members of a product line to behave differently. There are multiple ways this can be done. The simplest way is to add a mixset statement directly into a method, as seen on line 11 of the example below. In this example, the code on line 12 will only be part of the method if the World mixset is activated through a use statement or command line argument.

The second way to use mixsets with methods is to create mixsets that contain Umple aspects that inject code in methods. In the example below, the mixsets starting at lines 19, 27 and 35 all do this.

In Umple, code labels (identifiers followed by a colon) can be used to indicate variation points at multiple points among any method’s statements. These labels can be utilized by aspects to indicate where to inject code into the methods, and can even enable replacing the code between two labels. The injected code has direct access the local scope (i.e. local variables) at the locations where it is injected. When combined with mixsets, aspect injection at labels therefore provides fine grained variability at the statement level. It can be used as an alternative to the approach of using hook methods (empty methods that are called and do nothing by default but can be overridden in subclasses) to provide variability.

The main method in the example below contains three labels: Hello_Label, Beautiful_Label, and Wonderful_Label. They are utilized by the aspects of three mixsets (Hello, Beautiful, and Wonderful) to inject some print statements.

Example

class Main
{
  // The method below has three code labels
  // plus an inline mixset (line 11). 
  // These labels act as points of extensions.
  
  void main(String[] arg){
    Hello_Label: ;
    Beautiful_Label: ;
    Wonderful_Label: ;
    mixset World {
      System.out.print(" world !"); 
    } 
  }
}

// The following three mixsets inject code 
// based on the label specified after "before".
mixset Hello {
  class Main
  {
    before Hello_Label: main(String) {
      System.out.print(" Hello ");    
    }
  }
}
mixset Beautiful {
  class Main
  {
    before Beautiful_Label: main(String) {
      System.out.print(" beautiful ");     
    }
  }
}
mixset Wonderful {
  class Main
  {
    before Wonderful_Label: main(String) {
      System.out.print(" wonderful ");
    }
  }
}

// use statements activate mixsets.
use Hello;
use Beautiful;
//use Wonderful;
use World;
      

Load the above code into UmpleOnline

 

Syntax


aspectBody- : ([=operationSource:custom
    |generated
    |all])? ([!codeLabel:\S+:])? [[injectionOperation]] ( , [[injectionOperation]] )* ([[codeLang]] [[codeLangs]])? { [**code] } ( [[moreCode]] )*

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

mixsetInnerContent- : { [[extraCode]] | [[reqImplementation]] }