--- title: Behavioral Modeling - Power Window ... # Modeling variability and structures with variability ## Feature modeling ### Metamodel ```clafer abstract final Feature abstract final FeatureModel ``` ### Model ```clafer WinFeatures : FeatureModel manualUpDown : Feature express : Feature ? pinchProtection : Feature ? ``` ## Structural modeling ### Metamodel ```clafer abstract final Component abstract Port abstract final Command abstract State abstract StateMachine ``` ### Model Commands and requests. ```clafer motorUp : Command motorStop : Command motorDown : Command abstract final UserRequest up : UserRequest expressUp : UserRequest ? stop : UserRequest down : UserRequest ``` Window motor ```clafer WinMotor : Component cmd : Port -> Command ``` Window controller ```clafer abstract WinController : Component final motor -> WinMotor pinchDetector : Component ? req : Port -> UserRequest ? endOfTravel : Port ? objectDetected : Port ? [ lone (req, endOfTravel, objectDetected )] final xor WinStates : StateMachine xor movingUp : State [ motor.cmd = motorUp ] [ req=down --> movingDown ] [ endOfTravel --> closed ] [ req=up --> movingUp ] initial basic : State [ req=stop --> stopped ] [ req=expressUp --> movingUpX ] movingUpX : State [ this -[objectDetected]-> stopped ] initial xor stopped : State [ motor.cmd = motorStop ] closed : State [ req=down --> movingDown ] [ (req=up || req=stop) --> closed ] partlyOpen : State [ req=up --> movingUp ] [ req=down --> movingDown ] [ req=stop --> partlyOpen ] open : State [ req=up --> movingUp ] [ (req=down || req=stop) --> open ] movingDown : State [ motor.cmd = motorDown ] [ req=up --> movingUp ] [ endOfTravel --> open ] [ req=stop --> stopped ] [ req=down --> movingDown ] ``` ## Variability in structural models ### Linking the feature with the optional component (structural variability) The component `pinchDetector` is only required if we support the feature `pinchProtection`. ```clafer [ pinchProtection <=> pinchDetector ] ``` ### Disabling `objectDetected` port Without the feature `pinchProtection`, the port `objectDetected` should be inactive. Having the feature will allow receiving the signal `objectDetected`. ```clafer [ no pinchProtection => no WinController.objectDetected ] ``` ### Alphabet variability The user request `expressUp` is only available when the feature `express` is present. ```clafer [ express <=> expressUp ] ``` ## Variability in Behavior Using Inheritance Two kinds of window controllers: ### With continuous chime ```clafer WinCtrWithContChime : WinController ? chime : Port ? [ movingUpX <=> chime ] ``` ### With intermittent chime ```clafer WinCtrWithChime : WinController ? chime : Port ? [ no movingUpX => no chime ] [ chime --> no chime ] [ no chime && movingUpX --> (movingUpX => chime) ] ```