有限状态机模式 - 唯一的真模式? [英] Finite State Machine Pattern - The One True Pattern?

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

问题描述

都可能code写过提高通过采用状态机模式?

Could all Code ever written be improved by applying the State Machine Pattern?

我工作的一个项目,是可怕的可怕,越野车,碎面条code的质量。
我从这个博客复制 Martin Fowler的例子​​状态机code和转化的整个堆废话成一系列语句。
从字面上看只是一个状态,事件,转换和命令的列表。

I was working on a project that was a mass of horrendous awful, buggy, broken spaghetti code. I copied Martin Fowler's example State Machine code from this blog and transformed the whole heap of crap into a series of statements. Literally just a list of States, Events, Transitions and Commands.

我无法相信的转变。在code是现在干净,工作。当然,我知道之前状态机,并已实施,甚至他们
但在Martin Fowler的例子​​模型/配置的分离是惊人的。

I can't believe the transformation. The code is now clean, and works. Of course i was aware of State Machines before and have even implemented them but in the Martin Fowler example the separation of model/configuration is amazing.

这让我觉得,几乎所有我做过的这一做法某种程度上可以受惠。我想在我用每一种语言此功能。
也许这甚至应该是一个语言水平的功能。

This makes me think that almost everything i've ever done could have benefitted in some way from this approach. I want this functionality in every language i use. Maybe this should even be a language level feature.

有人认为这是错的?
或任何人有不同的模式有类似的经历?

Anyone think this is wrong? Or anyone have a similar experience with a different pattern?

推荐答案

有限状态机(FSM的),更具体地域专用语言(DSL的)更容易地匹配的问题的一个具体的解决方案的域,通过描述在溶液中一个专门的语言。

Finite state machines (FSM's) and more specifically domain specific languages (DSL's) make it easier to match a problem to one specific solution domain, by describing the solution in a specialised language.

状态机模式的局限在于,它本身就是一种编程语言,而是一个你必须写你自己的执行,测试和调试工具;一,任何维护者学习。您已经移动你的code的复杂性成为一个复杂的状态机的配置。有时,这是非常有用的,但肯定不是普遍的。

The limitations of the State Machine pattern is that it itself constitutes a programming language, but one for which you have to write your own execution, testing and debugging tools; and one which any maintainer has to learn. You have moved the complexity of your code into a complex FSM configuration. Occasionally, this is useful, but certainly not universally.

和因为任何冯·诺依曼计算机本身就是一个FSM,那么肯定任何程序的可以以这种方式重铸。

And since any von Neumann computer is itself a FSM, then certainly any program can be recast in this fashion.

这篇关于有限状态机模式 - 唯一的真模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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