无状态 vs 有状态 [英] Stateless vs Stateful

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

问题描述

我对关于编程中的无状态和有状态设计的一些具体信息的文章很感兴趣.我很感兴趣,因为我想了解更多关于它的信息,但我真的找不到任何关于它的好文章.我在网上阅读了几十篇文章,这些文章含糊地讨论了这个主题,或者他们在谈论 Web 服务器和会话——它们也是有状态与无状态",但我对编码中的无状态与有状态属性设计感兴趣.示例:我听说 BL 类在设计上是无状态的,实体类(或者至少我是这么称呼它们的 - 比如 Person(id, name, ..))是有状态的,等等.

I'm interested in articles which have some concrete information about stateless and stateful design in programming. I'm interested because I want to learn more about it, but I really can't find any good articles about it. I've read dozens of articles on the web which vaguely discuss the subject, or they're talking about web servers and sessions - which are also 'bout stateful vs stateless, but I'm interested in stateless vs stateful design of attributes in coding. Example: I've heard that BL-classes are stateless by design, entity classes (or at least that's what I call them - like Person(id, name, ..)) are stateful, etc.

我认为了解这一点很重要,因为我相信如果我能理解它,我就能写出更好的代码(例如考虑粒度).

I think it's important to know because I believe if I can understand it, I can write better code (e.g. granularity in mind).

无论如何,真的很短,以下是我所知道的关于有状态与无状态的区别:

Anyways, really short, here's what I know 'bout stateful vs stateless:

有状态(如 WinForms):存储数据以供进一步使用,但限制了应用程序的可扩展性,因为它受 CPU 或内存限制

Stateful (like WinForms): Stores the data for further use, but limits the scalability of an application, because it's limited by CPU or memory limits

无状态(就像 ASP.NET - 尽管 ASP 试图通过 ViewStates 保持状态):动作完成后,数据被传输,实例被交回线程池(Amorphous).

Stateless (Like ASP.NET - although ASP tries to be stateful with ViewStates): After actions are completed, the data gets transferred, and the instance gets handed back to the thread pool (Amorphous).

如您所见,它的信息非常模糊且有限(并且非常专注于服务器交互),因此如果您能为我提供一些更美味的信息,我将不胜感激:)

As you can see, it's pretty vague and limited information (and quite focussed on server interaction), so I'd be really grateful if you could provide me with some more tasty bits of information :)

推荐答案

我建议你从开始StackOverflow 中的问题 讨论了无状态编程的优点.这更多是在函数式编程的上下文中,但您将阅读的内容也适用于其他编程范式.

I suggest that you start from a question in StackOverflow that discusses the advantages of stateless programming. This is more in the context of functional programming, but what you will read also applies in other programming paradigms.

无状态编程与函数的数学概念有关,当使用相同的参数调用时,总是返回相同的结果.这是函数式编程范式的一个关键概念,我希望您能够找到该领域的许多相关文章.

Stateless programming is related to the mathematical notion of a function, which when called with the same arguments, always return the same results. This is a key concept of the functional programming paradigm and I expect that you will be able to find many relevant articles in that area.

您可以研究以获得更多理解的另一个领域是 RESTful Web 服务.与试图以某种方式保持状态的其他 Web 技术相比,这些设计为无状态".(事实上​​,您所说的 ASP.NET 是无状态的是不正确的 - ASP.NET 努力使用 ViewState 来保持状态,并且肯定会被描述为有状态的.另一方面,ASP.NET MVC 是一种无状态技术).有很多地方讨论 RESTful Web 服务的无状态"(例如 this 博客点),但您可以再次从 SO 问题.

Another area that you could research in order to gain more understanding is RESTful web services. These are by design "stateless", in contrast to other web technologies that try to somehow keep state. (In fact what you say that ASP.NET is stateless isn't correct - ASP.NET tries hard to keep state using ViewState and are definitely to be characterized as stateful. ASP.NET MVC on the other hand is a stateless technology). There are many places that discuss "statelessness" of RESTful web services (like this blog spot), but you could again start from an SO question.

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

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