在OSWorkflow中最讓人惱火的就是它的接口定義!我會就這些接口的混亂展開一系列的分析,今天先說說Configuration接口

          偶繼承了它的Configuration接口

          import com.company.engine.workflow.store.IWorkFlowStore;
          import com.opensymphony.workflow.StoreException;
          import com.opensymphony.workflow.config.Configuration;
          import com.opensymphony.workflow.spi.WorkflowStore;

          public interface IConfiguration extends Configuration
          {
           /**
            * @deprecated getIWorkflowStore()
            */
              WorkflowStore getWorkflowStore() throws StoreException;
             
              /**
               * return WorkFlowStore which implements the interface of IWorkFlowStore
               * @return
               * @throws StoreException
               */
              IWorkFlowStore getIWorkflowStore() throws StoreException;
             
          }

          你可能奇怪我為何要繼承它的接口(肯定是Bad smell),原因如下,

          IWorkFlowStore 接口定義

          import com.opensymphony.workflow.StoreException;
          import com.opensymphony.workflow.spi.Step;
          import com.opensymphony.workflow.spi.WorkflowEntry;
          import com.opensymphony.workflow.spi.WorkflowStore;

          public interface IWorkFlowStore extends WorkflowStore
          {
           
           public Step createCurrentStep(WorkflowEntry _entry , Step _step) throws StoreException;

          }

          WorkflowStore接口定義

              /**
               * Persists a step with the given parameters.
               *
               * @param entryId The workflow instance id.
               * @param stepId the ID of the workflow step associated with this new
               *               Step (not to be confused with the step primary key)
               * @param owner the owner of the step
               * @param startDate the start date of the step
               * @param status the status of the step
               * @param previousIds the previous step IDs
               * @return a representation of the workflow step persisted
               */
              public Step createCurrentStep(long entryId, int stepId, String owner, Date startDate, Date dueDate, String status, long[] previousIds) throws StoreException;

          看到了吧?

          其實(shí)我只是希望在createCurrentStep時按照OO的方法執(zhí)行,而不是傳遞那些"Bad Smell"的參數(shù),而OSWorkflow中的WorkflowStore是需要Configuration來獲取的,此時為了增加一個看似合理的方法,需要分別繼承Configuration與WorkflowStore;這還沒有完,你需要實(shí)現(xiàn)一個Configuration實(shí)現(xiàn)!!

          import com.company.engine.workflow.store.IWorkFlowStore;
          import com.opensymphony.workflow.StoreException;
          import com.opensymphony.workflow.config.DefaultConfiguration;
          import com.opensymphony.workflow.spi.WorkflowStore;

          public class DefaultIConfiguration extends DefaultConfiguration implements IConfiguration
          {
           
              public static DefaultIConfiguration INSTANCE = new DefaultIConfiguration();
              private transient IWorkFlowStore store = null;

           /**
            * @deprecated getIWorkflowStore()
            */
           public WorkflowStore getWorkflowStore() throws StoreException
           {
            return null;
           }

           public IWorkFlowStore getIWorkflowStore() throws StoreException
           {
            if (store == null)
            {
             String clazz = getPersistence();

             try
             {
              store = (IWorkFlowStore) Class.forName(clazz).newInstance();
             }
             catch (Exception ex)
             {
              throw new StoreException("Error creating store", ex);
             }

             store.init(getPersistenceArgs());
            }

            return store;
           }

          }

          總結(jié)

          1。OSWorkflow與WorkflowStore接口的關(guān)系比較的微妙,它需要借助于Configuration接口的實(shí)現(xiàn)來獲取到實(shí)際的WorkflowStore對象。

          2。由于這樣的一種微妙關(guān)系,對WorkflowStore接口的擴(kuò)展必將連帶著需要擴(kuò)展Configuration接口,而產(chǎn)生這樣的"果凍效應(yīng)"的罪魁禍?zhǔn)拙褪怯捎赪orkflowStore接口與Configuration接口耦合的太緊。

          3。OSWorkflow并沒有很好的遵守OO的設(shè)計(jì)規(guī)則,尤其在它的參數(shù)傳遞上,非常的差!

          主站蜘蛛池模板: 霞浦县| 清丰县| 河源市| 雅江县| 左权县| 海门市| 阳泉市| 莫力| 南溪县| 祁阳县| 通河县| 石渠县| 龙游县| 怀安县| 洛扎县| 扎赉特旗| 和平区| 麻城市| 岗巴县| 积石山| 仙桃市| 泸定县| 微博| 虎林市| 仁化县| 白玉县| 精河县| 宁蒗| 兴安盟| 博野县| 如皋市| 凉城县| 西乌珠穆沁旗| 江口县| 彭州市| 齐齐哈尔市| 乌审旗| 喀什市| 桃源县| 永年县| 泸州市|