GUI作为有限状态机 [英] GUI as a finite state machine

查看:268
本文介绍了GUI作为有限状态机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要实现应用程序的GUI,我希望将所有逻辑从一个表单转移到另一个集中式。这个GUI管理器将表现为有限状态机。虽然我认为我已经在某个地方看到了这种实现,但我找不到与这种解决方案相匹配的设计模式。



表单将如下所示:

  public class登录:Form 
{
...

private void EnterButton_Click()
{
...

string user = loginTextBox.Text;
string password = passwordTextBox.Text;
bool isValid = SecurityManager.CheckUserLogin(user,password);

GUIManager.FormEnd(FormLogin,new LoginData(user,pass,isValid));
}

...
}

GUI管理器将执行以下操作:

  public class GUIManager 
{
...

public void FormEnd(FormType type,FormData data)
{
switch(type)
{
...
case FormLogin:
LoginData ld =(LoginData)数据;
if(ld.Valid)
{
m_loginForm.Hide();
m_mainForm.Show();
}
...
}
}

...
}
/ pre>

达到这一点我有以下问题:是否有一个设计模式,正式化这个想法?如果有,.NET是否支持它?如果没有,听起来好像是一个好的实现想法?谢谢!

解决方案

这是一个好主意!事实上,事实上,之前已经做了,可能是可扩展应用程序开发中最常用的模式(想到像Visual Studio,Eclipse等IDE)。



一个例子,来自MS模式和实践组的SCSF(利用CAB)使用这种开箱即用的模式来在WinForms和WPF中构建可插拔和可扩展的组合应用程序。它使用的实际模式包括构造称为WorkItems的分层状态机,它们控制应用程序并流过应用程序。我会研究模式和实践(People&我曾多次使用它,这非常值得。


To implement application's GUI I would like to have all the logic to go from one form to another centralized. This GUI manager will behave as a finite state machine. Although I think I have seen this kind of implementation somewhere, I can't find a design pattern that matches with this kind of solution.

A form will look like this:

public class Login : Form
{
    ...

    private void EnterButton_Click()
    {
        ...

        string user = loginTextBox.Text;
        string password = passwordTextBox.Text;
        bool isValid = SecurityManager.CheckUserLogin(user,password);

        GUIManager.FormEnd(FormLogin,new LoginData(user, pass, isValid));
    }

    ...
}

And the GUI manager will do something like this:

public class GUIManager
{
    ...

    public void FormEnd(FormType type, FormData data)
    {
        switch (type)
        {
            ...
            case FormLogin:
                LoginData ld = (LoginData)data;
                if (ld.Valid)
                {
                    m_loginForm.Hide();
                    m_mainForm.Show();
                }
            ...
        }
    }

    ...
}

Reaching this point I have the following questions: is there a desing pattern that formalizes this idea? If there is, does .NET support it somehow? If there isn't, does it sound like a good implementation idea? Thanks!

解决方案

It's a great idea! So great, in fact, that it's been done before and is probably the most common pattern used in extensible application development (think of IDEs like Visual Studio, Eclipse and the like).

One example, SCSF (which leverages CAB), from the MS Patterns and Practices Group, uses this pattern out-of-the-box to construct pluggable and extensible composite applications in both WinForms and WPF. The actual pattern it uses involves construction of hierarchical state machines called WorkItems that control usecases and flow through the application. I'd look into how the Patterns and Practices guys did it before I implement it as my own brainchild. I've used it on many occasions and it's well worth it.

这篇关于GUI作为有限状态机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆