forked from alibaba/COLA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TransitionsBuilderImpl cannot be inherited from TransitionBuilderImpl…
… because they are at the same level and should not be in a parent-child relationship. If it is inheritance, the TransitionBuilderImpl should include the TransitionsBuilderImpl responsibility, which violates the single principle
- Loading branch information
1 parent
aa7f604
commit afe5e99
Showing
3 changed files
with
46 additions
and
16 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...achine/src/main/java/com/alibaba/cola/statemachine/builder/AbstractTransitionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.alibaba.cola.statemachine.builder; | ||
|
||
import com.alibaba.cola.statemachine.State; | ||
import com.alibaba.cola.statemachine.impl.StateHelper; | ||
import com.alibaba.cola.statemachine.impl.TransitionType; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Take TransitionBuilderImpl and TransitionsBuilderImpl sharing variables | ||
* and methods to that abstract class, which acts as their parent, | ||
* instead of having TransitionsBuilderImpl inherit from | ||
* TransitionsBuilderImpl. I think that the multi-flow | ||
* builder(TransitionsBuilderImpl) and single-flow | ||
* builder(TransitionBuilderImpl) are equal and not supposed to be | ||
* parent-child relationship, they from, when, and perform methods | ||
* are not the same, and although it looks like just a set of loops | ||
* but logically should not be inherited over Override. | ||
* ( Just as there was no relationship, why should we talk to each other, | ||
* say a we are not suitable). With the abstract class, multi-flow and single-flow | ||
* only use to focus on their respective functions are single-flow, | ||
* or multi-flow. Conform to a single duty. | ||
* @author welliem | ||
* @date 2023-07-14 12:13 | ||
*/ | ||
abstract class AbstractTransitionBuilder<S,E,C> implements From<S,E,C>,On<S,E,C>,To<S,E,C>{ | ||
|
||
final Map<S, State<S, E, C>> stateMap; | ||
|
||
protected State<S, E, C> target; | ||
|
||
final TransitionType transitionType; | ||
|
||
public AbstractTransitionBuilder(Map<S, State<S, E, C>> stateMap, TransitionType transitionType) { | ||
this.stateMap = stateMap; | ||
this.transitionType = transitionType; | ||
} | ||
@Override | ||
public To<S, E, C> to(S stateId) { | ||
target = StateHelper.getState(stateMap, stateId); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters