请让我知道以下哪一项是好的编程习惯:
1. 使用静态类,然后使用类 MainWindow 构造函数对其的引用,如下所示:
public partial class Mainwindow : Window
{
public MainWindow()
{
InitializeComponent();
UI.window = this;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Shutdownads attempt1 = new Shutdownads();
}
}
static class UI
{
public static MainWindow window;
}
/*and then refering to the wpf elements from other classes as follows
UI.window.textbox.Text="blahblah"
UI.window.button ... and so on
*/
或者
2. 将我程序中的所有类都包含在 MainWindow 类中会更好吗?
或者
3. 有没有更好的选择(也可以实现更好的 OOP 以及我可以通过其他类访问 UI)?