2010-03-17 41 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; 
});