是否存在控制从属作业或从主站管理从属作业的设计模式?

时间:2014-08-10 11:11:10

标签: java algorithm oop design-patterns

管理或控制器设计模式。我有一个班在结构上做两个不同的工作。是否有一种设计模式以更加可维护的方式重构它?或者,我应该如何以更加可维护的方式划分这个类?

                     Management Class does

Task launching                            recovery management
- create Callable Task                   - if thread failed to start, re-assign 
- submit tasks to ExecutorService              the same task to other thread 
- start ExecutorService                  - if task is not halted unexpectedly,
- get result of each task                      re-assign the task to new thread
                                         - if thread halted, get already done 
                                               job and restart the thread for
                                               not done jobs
                                         - other task and thread related recovery
                                               scenarios

Settings
- set requirements of management class in system level
- determine optimal number of threads should be run
- determine optimal number of task to be created
- create and manage system configuration file - store system settings, get system
  settings-

在进行投票或试图关闭之前,如果你是建设性的,请写评论,以便我解决它。

1 个答案:

答案 0 :(得分:0)

您想申请SRP:Single Responsibility principle

事实上,在你的情况下,你的实际课程做得太多了:它有三个职责:

  1. 配置线程池
  2. 启动任务
  3. 恢复失败的任务
  4. 我会把你的全班分成三个班级:

    1. 设置(设置)
    2. TaskExecutor(启动器)
    3. FailedTaskRecoverer(recoverer)
    4. 请注意,它不是设计模式,而是SOLID原则的一部分。