2010-03-17 28 views
1

下面是簡單的僞代碼:什麼是MVC相當於這段代碼:

void TextBox1Changed() 
{ 
    //If the text isn't a number, color it red 

    if (!IsValidNumber(TextBox1.Text) 
     TextBox1.Color = Pink; 
    else 
     TextBox1.Color = WindowColor; 
} 

什麼是MVC enterprisey版本?

+0

你能告訴我們你在說什麼mvc框架嗎?如果是網絡的發展這應該使用JavaScript來完成,因此將是對所有服務器端Web框架相同。 – 2010-03-17 20:24:45

回答

0

並不想成爲特定語言,但這個想法是創建一個知道,如果該值有效的一些文本控件。這很容易對M,V,和C的確切角色先掛了。然而,所有的實際目的,是有意義的視角和類似應用的控制器桌面結合起來。 Swing採取了這種方法,因爲控制器和視圖具有非常緊密的耦合,並且將它們合併爲一個有意義。讀了這個nice discussion C2上的話題。

class NumberTextBox extends TextBox { 
    bool isValid() { 
     return IsValidNumber(this.Value); 
    } 
} 


ageTextBox = new NumberTextBox(); 
ageTextBox.addChangeHandler(function() { 
    this.Color = this.isValid ? WindowColor : Pink; 
});