2013-04-10 24 views
1

我希望能夠跟蹤用戶在特定UI表單上進行的操作。如何跟蹤對UI表單的更改?

例如 - 用戶從組合框中選取產品,填寫文本字段等。 某些字段是有條件的,這意味着只有在選擇了某些先前的選項時它們纔可見。

我希望能夠在任何特定時刻跟蹤他的選擇 - 基本上我希望報告由用戶填寫表單時所用的單個事件組成。

我想Chain of Responsibility模式的變化:

public interface Chain{ 
    setNextChain(Chain next); 
    getNextChain(); 
    setPrevChain(Chain prev); 
    getPrevChain(); 
} 

public class Field implements Chain { 
     // All of the chaining implementation... 
     // All of the Action's members... 
     private string[] actionData; 
    } 

public class Product extends Field{ 
     // old Product logic integrated within the chain... 
    } 

public class AdName extends Field{ 
     // old Product logic integrated within the chain... 
    }  

不知道這是否是正確的做法,並希望在設計你的看法。

+0

我想你正在尋找Builder模式 – 2013-04-10 14:13:48

回答

1

這個想法是好的,但對我來說,它看起來更像是一個列表CommandsCommand pattern通常用於記住用戶操作,在需要時可以輕鬆撤消。

「責任鏈」模式並不完全是您在這裏需要的,因爲您的Field對象實際上並不需要對前一個元素和下一個元素的引用。唯一需要用戶執行的操作列表。因此,您不需要使用getNext()/ getPrevious()方法的接口Chain。您基本上可以將所有Field實例保存在List中,並向前/向後導航列表。

interface Command { 
} 

class ProductSelection implements Command { 
    Product selectedProduct; 
} 

class AdNameSelecton implements Command { 
    String selectedAdName; 
} 

List<Command> actions = new ArrayList<Command>(); 

// when user selects product 
actions.add(new ProductSelection(product)); 
// when user selects ad name 
actions.add(new AdNameSelection(name));