2012-10-25 67 views
0

我想編寫一個監督和管理項目值的DesignManager類。爲值設置和驗證反饋設計管理器類

項目有很多屬性和相互依賴關係,併爲對方設置了某些值規則。這些值在UI級別輸入到Item變量中,DesignManager檢測變化,進行驗證/計算並向UI報告(通過事件)。

我現在的問題是圍繞屬性setter模式旋轉。我想到了2種方式來完成的關係,各有其利弊/利弊,希望得到建議使用哪一個:

// Syntax is cleaner 
// DesignManager does not know about the change Item notifies DesignManager 
// Nested collections can notify DesignManager, but there is problem of identifying the sender 
DesignManager.Item.Property = value; 

// Syntax is not clean 
// Hard to support value setting of nested Items or collections within Items 
// DesignManager immediately gets informed of the change via the calling UI logic. 
DesignManager.SetItemProperty(value); 

我不知道我喜歡哪一個,因爲我不能看到所有的注意事項與每一個相關。目前,我最大的問題是嵌套在Item中。

如果有人有這方面的經驗,希望可以建議。謝謝。

回答

0

這是從C#數據庫映射LINQ一個片段:

public int id 
    { 
     get 
     { 
      return this._id; 
     } 
     set 
     { 
      if ((this._id != value)) 
      { 
       this.OnidChanging(value); 
       this.SendPropertyChanging(); 
       this._id = value; 
       this.SendPropertyChanged("id"); 
       this.OnidChanged(); 
      } 
     } 
    } 

微軟還去第三種方式和使用屬性,其設定的功能火災事件中。 交換事件在更改之前發送,因此可用於否決更改(未從MS實施)。 Microsoft不會爲每個類的屬性進行分離,只有一個事件包含該屬性的名稱。 在您的經理中,您可以訂閱事件並根據需要驗證/計算屬性。