方法调用序列:设计模式/面向对象设计

时间:2016-06-22 18:31:35

标签: java oop design-patterns

问题

我正在开发一个UI框架,它需要根据输入序列在一个序列中动态调用方法和页面对象。我主要想用更好的OO方式替换Switch / If else以使扩展更容易

所有页面都扩展了Base Abstract类,并且这些方法扩展了另一个基本Action类。我有注释来识别类和方法。我需要构建一个方法列表,这些方法将由框架以相同的顺序为每个测试用例调用。

我使用BDD作为输入,即

场景:测试交易成功页面

  1. 鉴于用户登录
  2. 并执行一些操作
  3. 然后显示交易成功页面
  4. 因此,每个步骤都映射到一个Action类,该类执行一组Actions。我正在使用注释来查找Action类。

    //Sample JBehave Steps Pojo
    @Given
    public void login(String user)
    {
     //Action to be performed is Login. Search for the Login Action class
    
    }
    
    @And
    public void performSomeAction(String action , String component)    
    {
    Find the class representing this action
    }
    
    
    //Page Objects
    ClassMap(name="loginPage")
    public class LoginPage extend Page
      {
    
        MethodMap(action="test"  , component="test")
        public BaseStep login extends BaseStep
        {
           // returns a login step
        }
    
      }
    
        //Building the method sequence
        //Now each Test Step is mapped to a class
        for(Action : Actions to be performed)
        {
         //Check if the action / component maps to a method and a class
        switch(action)
       {
          case VERIFY:
             //Invoke the Method Verify
          case LOAD :
             //Invoke the Method Load
          case ACTION1 :
             //Perform some action
       }
    

    我正在寻找一种设计模式来实现相同而不使用switch else。一个适合的好设计模式就是我要看的。

0 个答案:

没有答案