| | 17 | |
|---|
| | 18 | Signals |
|---|
| | 19 | ~~~~~~~ |
|---|
| | 20 | UML elements should emit signals if their state changes. This can be done |
|---|
| | 21 | by means of the misc.signal.Signal class. All what's left is to define a |
|---|
| | 22 | protocol (the arguments that the UML element supplies). |
|---|
| | 23 | |
|---|
| | 24 | The following cases can occur: |
|---|
| | 25 | 1. Unidirectional relationships or attributes: |
|---|
| | 26 | a. Set data |
|---|
| | 27 | b. Set data and overwrite old data |
|---|
| | 28 | c. Remove the attribute |
|---|
| | 29 | 2. Bidirectional relationships |
|---|
| | 30 | a. multiplicity of '1' |
|---|
| | 31 | b. multiplicity of '*' |
|---|
| | 32 | |
|---|
| | 33 | For non-sequence attributes we can do something like this |
|---|
| | 34 | |
|---|
| | 35 | def signal_handler(attribute_name, old_value, new_value, *custom_args): |
|---|
| | 36 | pass |
|---|
| | 37 | |
|---|
| | 38 | where old_value and new_value is None (or the default value) in case no value |
|---|
| | 39 | was set before. |
|---|
| | 40 | |
|---|
| | 41 | For sequences we can only add and remove values. We can do this with the |
|---|
| | 42 | same amount of attributes, only old_value will be one of 'add' or 'remove' and |
|---|
| | 43 | new_value will contain the value that is added or removed. |
|---|
| | 44 | |
|---|
| | 45 | |
|---|
| | 46 | |
|---|