我最近得到了以下示例,其中我们将操作名称作为字符串传递给方法,然后该方法决定需要调用的函数。
这是解决问题的好方法,还是有更好的方法?
public static final String ACTION_CHARGING_REMINDER = "charging-reminder";
public static void executeTask(Context context, String action) {
if (ACTION_INCREMENT_WATER_COUNT.equals(action)) {
incrementWaterCount(context);
} else if (ACTION_DISMISS_NOTIFICATION.equals(action)) {
NotificationUtils.clearAllNotifications(context);
} else if(ACTION_CHARGING_REMINDER.equals(action)){
issueChargeReminder(context);
}
}
发布于 2018-05-15 18:02:03
这听起来很像react/redux,action/reduction模式。
Reducer指定应用程序的状态如何更改以响应发送到存储的操作。请记住,操作仅描述所发生的事情,而不描述应用程序的状态如何更改。
https://stackoverflow.com/questions/50340942
复制相似问题