The strategy pattern of design pattern — the callback design of operation and maintenance system
The basic principle of
-
Dynamic and static separation
-
Use composition more than inheritance
-
Interface oriented programming, not implementation oriented
Functional descriptions of interfaces and classes
- CallbackFlow: Abstracts an interface, which is a polymorphic interface for changing parts, because the updated service type is different and the process is different.
- CallbackHandler: Callback processing class, this class is mainly to handle the callback of system requests, will entrust the CallbackFlow class to fetch the data of the update process, and perform logical processing to get the current execution stage and finally return it to the user.
Implementations of interfaces, classes, and pseudocode
- Gets an abstract interface to the update process
package VoneCallback; import java.util.HashMap; Public interface CallbackFlow{// Get stage number of stages public int getStagecount(); Public String getFlowDesc(); Public String getChangeStatus(); Public void setChangeStatus(); }Copy the code
-
Get the concrete implementation of the K8S service update process
package VoneCallback; import java.util.HashMap; Public class CallbackK8sService implements CallbackFlow{@override public String getChangeStatus() {// Get data changes from redis return Status; } @Override public String getFlowDesc() { String Status = this.getChangeStatus(); If (status == "True"){// Get data from redis res = "get data from redis" this.setChangestatus (key); return res; } } @Override public void setChangeStatus(String key) { redis.set(key,"false"); } @Override public int getStagecount(String res) { return stagecount; }}Copy the code
-
Obtain host services
package VoneCallback; public class CallbackHostService implements CallbackFlow{ // the type of hosts service // to do } Copy the code
-
Callback handler class
package VoneCallback; public class CallbackHandler { CallbackFlow callbackflow; public CallbackHandler(){ callbackflow = new CallbackK8sService(); } public String getFlowData(){ String data = callbackflow.getFlowDesc(); } public String getResStatus(){ String Flowdata = getFlowData(); . return ResStatus; }}Copy the code