State 란?
Represents a distinct satge of an object's lifecycle. Different scenarios that an applcation object life cycle pasees through.
A state is denoted by a round-cornered rectangle with the name of the state written inside it.
예시.
The door can be in one of three states: "Opened", "Closed" or "Locked". It can respond to the events "Open", "Close", "Lock" and "Unlock".
Types of states in UML
1. Simple State
2. Composite State
3. Submachine State
예시
Simple state
No regions, No substates
STATE1 is a Composite state
STATE1 has 1 region
STATE1_x are substates of STATE1
STATE1 is also called superstate of STATE1_x
STATE1, STATE1_2 is a Composite state
STATE1, STATE1_2 has 1 region
STATE1_x are substates of STATE1
STATE1 is also called superstate of STATE1_x
STATE1_2 is superstate of STATE1_2_0 and STATE1_2_1
STATE1_x are 'direct' substate of STATE1
STATE1_2_x are 'indirect' substate of STATE1
Compartments of State
1. Name compartment
2. Internal activity compartment
3. Internal transition compartment
Internal activity compartment
- Syntax : <behavior lable>/<behavior expression>
- Internal activity label 로 예약된 Keyword들 : entry, exit, do
- entry : </behavior expression> will be excuted upon entry to the state (onetime execution)
- exit : </behavior expression> will be excuted upon exit from the state (onetime execution)
- do : </behavior expression> will be excuted as long as the object is in the state or until the computation specified by the expression is completed. (ongoing execution)
Transition이란?
A transition may have a trigger, a guard and an effect, as below. "Trigger" is the cause of the transition, which could be a signal, an event, a change in some condition, or the passage of time. "Guard" is a condition which must be true in order for the trigger to cause the transition. "Effect" is an action which will be invoked directly on the object that owns the state machine as a result of the transition.
- Syntax : <trigger>[<guard>]/</behavior expression>
Types of transition
1. External transition
2. Local transition
3. Internal transition
External transition
The source state signifies a change of state in the object's life cycle due incident of a trigger.
If the event occurence matches the 'trigger' and 'guard' of the internal transition evaluates to be TRUE, transition will be executed. Transitions are denoted by lines with arrowheads leading from a source state to a target state.
External transition 예시
Trigger 와 [guard], /<behavior expression> 은 optional로 생략될 수 있다.
External transition 시 action의 실행 순서
exit action은 innermost state부터 수행되고 entry action은 outermost state 부터 수행됨
Internal transition
If the event occurence matches the 'trigger' and 'guard' of the internal transition evaluates to be TRUE, then <behavior expression> will be executed without exiting or re-entering the state.
Internal transition 예시
Local transition
A local transition can only exist within a composite state.
Local transition 예시
Self transitions
A state can have a transition that returns to itself, as in the following diagram. This is most useful when an effect is associated with the transition.
State Machine 작성 시 알아둘 것
- doActivity behavior commences excution when the state is entered only after the state entry behavior has completed.
- entry, exit, do cannot be associated with any transition
- If all transitions into a state perform the same transition action, push the common action inside the state and make it to an entry action.
- If all transitions leaving from a state perform the same transition action, push the common action inside the state to make it an exit action.
Event (Trigger)란?
Events are incidents or a stimulus by which a state machine can be triggered. In state machine events cause transitions.
Components of Event
1. Signal
2. One or more associated values or parameters (optional)
예를들면 키패드에서 각각 숫자키가 눌린 것을 파라미터없이 이벤트로 볼 수도 있고, 아니면 숫자키 입력을 이벤트로 보고 어떤 숫자가 눌렸는지를 파라미터로 구분하는 방법이 있다.
Pseudo states 와 종류
1. Initial state
2. Choice state
3. Join state
4. Deep history state
5. Shallow history
Initial state
represents a starting point for a Region. When entered from the external world, initial pseudo state signifies that which state to be entered first.
Initial state에선 하나의 outgoing transition만 가질 수 있다.
또한 Initial state Transition은 Trigger, Guard는 없고 Action 만 있을 수 있다.
Final state
The final state is denoted by a circle with a dot inside.
Choice state
is shown as diamond-shaped symbol. It has a sing incoming transition and two or more outgoing transition.
outgoint transition 중에 적어도 하나의 guard는 만족해야 하기 때문에 [ELSE]를 사용하는게 권장된다.
Junction Pseudo-State
Junction pseudo-states are used to chain together multiple transitions. A single junction can have one or more incoming, and one or more outgoing, transitions; a guard can be applied to each transition. Junctions are semantic-free. A junction which splits an incoming transition into multiple outgoing transitions realizes a static conditional branch, as opposed to a choice pseudo-state which realizes a dynamic conditional branch.
Terminate Pseudo-State
Entering a terminate pseudo-state indicates that the lifeline of the state machine has ended. A terminate pseudo-state is notated as a cross.
History States
A history state is used to remember the previous state of a state machine when it was interrupted. The following diagram illustrates the use of history states. The example is a state machine belonging to a washing machine.
In this state machine, when a washing machine is running, it will progress from "Washing" through "Rinsing" to "Spinning". If there is a power cut, the washing machine will stop running and will go to the "Power Off" state. Then when the power is restored, the Running state is entered at the "History State" symbol meaning that it should resume where it last left-off.
Concurrent Regions
A state may be divided into regions containing sub-states that exist and execute concurrently. The example below shows that within the state "Applying Brakes", the front and rear brakes will be operating simultaneously and independently. Notice the use of fork and join pseudo-states, rather than choice and merge pseudo-states. These symbols are used to synchronize the concurrent threads.
출처 :
FastBit Embedded Brain Academy
https://sparxsystems.com/resources/tutorials/uml2/index.html
'임베디드 개발 > 펌웨어' 카테고리의 다른 글
메모리 인터페이스, SDRAM 인터페이스 (0) | 2023.03.20 |
---|---|
Fragmentation을 피하기 위한(안전한) UDP payload size (0) | 2023.03.20 |
터미널 제어문자 ANSI escape code / 터미널에 글자색 배경색 입히기 (0) | 2023.02.20 |
CAN FD 프로토콜 (0) | 2023.02.20 |
YMODEM, XMODEM 프로토콜 (0) | 2023.02.15 |