使用vb.net表格的状态机 [英] State Machine using vb.net form

查看:66
本文介绍了使用vb.net表格的状态机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何使用VB.NET窗口而不是WPF来制作状态机吗?

下面的链接在解释它方面做得很好,但是我想知道是否还有更好的方法.

http://www.splatco.com/fsm_tute/fsm_tute17.htm [

Can someone tell me how to make a state machine using VB.NET window form not WPF?

The link below does a great job explaining it, but I was wondering if there are better one.

http://www.splatco.com/fsm_tute/fsm_tute17.htm[^]

推荐答案

该链接实际上是国家的一个非常糟糕的例子.闻起来真难闻.案例陈述被认为是难闻的气味(马丁·福勒),请参阅[ ^ ].您要为从接口继承的每个状态创建一个类.这是几个网页:

http://sourcemaking.com/design_patterns/state/c%2523 [ http://www.blackwasp.co.uk/State.aspx [ ^ ]

也可以在Wikipeida中查找气味: http://en.wikipedia.org/wiki/Code_smell [ ^ ]
That link is actually a really bad example of state. It has a really bad smell; A case statement is considered a bad smell (Martin Fowler), see [^]. What you want to do is create a class for each state which inherits from an interface. Here is a couple of web pages:

http://sourcemaking.com/design_patterns/state/c%2523[^] or http://www.blackwasp.co.uk/State.aspx[^]

Also can look up smells in Wikipeida: http://en.wikipedia.org/wiki/Code_smell[^]


您显示的代码示例为状态机的一个非常非常糟糕的例子.此外,特定的UI库与有限状态机(FSM)无关,但是可以使用有限状态机来建模和操作具有状态的许多对象,包括UI的状态. 使用窗口表单或WPF制作状态机"的概念只是荒谬的.

克利福德·尼尔森(Clifford Nelson)的回答很有用.我想从不同的角度为您提供一些想法.
首先,请参阅:
http://en.wikipedia.org/wiki/Finite-state_machine [ ^ ].

让我解释一下如何通过集合论从第一条原则来制定FSM( http://en.wikipedia.org/wiki /Set_theory [ ^ ]).令 S 为一些状态的集合. S中的任何设置元素s都可以表示系统的当前状态.我们需要一个显示状态之间所有可能的过渡的结构.如果我们有一组来自S的开始状态(过渡之前)s和一组来自S的结束状态(过渡之后)e,那么有序对(s, e)的集合将代表所有可能的状态转换.该集合称为集合SS X S上的笛卡尔平方,其中每个(s, e)是元素S X S. (请参见 http://en.wikipedia.org/wiki/Cartesian_product [ 枚举类型不枚举!解决.NET和语言限制 [
本文介绍了如何基于由代表状态集的枚举类型定义的状态集来构建功能齐全的有限状态机. CartesianSquareIndexedArray类表示FSM转换容器的索引基础.

—SA
The code sample you show is really, really bad example of state machine. Also, particular UI libraries have nothing to do with finite-state machines (FSM), but the finite-state machines could be used to model and operate with many objects with states, including the state of the UI. The notion of "making state machine using window form or WPF" is just an absurd.

The answer by Clifford Nelson is useful. I want to provide give you some ideas from a different stand point.
First of all, please see:
http://en.wikipedia.org/wiki/Finite-state_machine [^].

Let me explain how a FSM can be formulated from the first principles, via the set theory (http://en.wikipedia.org/wiki/Set_theory[^]). Let S be a set of some states. Any set element s from S can represent a current state of the systems. We need a structure showing all possible transitions between the states. If we have a set of starting states (before transition) s from S and ending states (after transition), e from S, then the set of ordered pairs (s, e) will represent the set of all possible state transitions. This set is called the Cartesian square on the set S, S X S, where each (s, e) is an element S X S. (See http://en.wikipedia.org/wiki/Cartesian_product[^].)

The Cartesian square represent the set of all thinkable transition. To mark just the permitted transition, we need to take any subset of the Cartesian square. This subset is a set of values defined of the array NxN, where N is the total number of states. What would be those values? It we need them only to represent a subset (and consequently the set of permitted transitions), it would be just the array of Boolean values. Formally, this enough to define a particular FSM.

In real life, however, the value of these array (or a more dedicated class providing array-like interface, please see below the reference to my article) is a good place to put some valuable technical information. For example, in the machine control systems I created, I used that value to place the algorithm of transition, including preconditions (measured via digital inputs of the digital I/O system), expected post-condition, sequence of output operations via digital I/O, expected processing time, timeouts, etc. Even each of the values for prohibited transition is useful. I used it to place a string format used to generate a message explaining why one or another transition is actually not allowed.

Please see my article Enumeration Types do not Enumerate! Working around .NET and Language Limitations [^], in particular, the section "3.6 Cartesian Square".

This article explains how to build a really functional finite-state machine based on a set of state defined by an enumeration type representing the set of states. The class CartesianSquareIndexedArray represent the indexing base to the container of FSM transitions.

—SA


作为一般的经验法则,表单及其控件不存储数据也不维护数据对象的状态.表单仅应保持表单的视觉状态,例如表单将如何操作数据对象,并向用户展示数据模型的视图.

类维护数据模型,并公开用于用户界面的方法来操纵该模型,无论是Windows Forms应用程序,ASP.NET应用程序,WPF应用程序还是其他某种表示技术.地狱,您甚至可能不需要UI层,例如Web服务.

尝试对数据模型类进行编码,以使它们根本不需要用户界面.
As a general rule of thumb, forms and their controls do not store data or maintain the state of a data object. Forms should only maintain the visual state of the form, such as how a form is going to manipulate a data object, and present the user a view of the data model.

Classes maintain the data model and expose methods for a user interface to manipulate that model, be it by Windows Forms app, ASP.NET app, a WPF app, or some other presentation technology. Hell, you might not even need a UI layer, such as the case with Web Services.

Try to code your data model classes so they don''t need a user interface at all.


这篇关于使用vb.net表格的状态机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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