Stateless vs Stateful

前端 未结 8 1319
暖寄归人
暖寄归人 2020-11-28 18:31

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, b

相关标签:
8条回答
  • 2020-11-28 18:39

    Money transfered online form one account to another account is stateful, because the receving account has information about the sender. Handing over cash from a person to another person, this transaction is statless, because after cash is recived the identity of the giver is not there with the cash.

    0 讨论(0)
  • 2020-11-28 18:39

    We make Webapps statefull by overriding HTTP stateless behaviour by using session objects.When we use session objets state is carried but we still use HTTP only.

    0 讨论(0)
  • 2020-11-28 18:40

    The adjective Stateful or Stateless refers only to the state of the conversation, it is not in connection with the concept of function which provides the same output for the same input. If so any dynamic web application (with a database behind it) would be a stateful service, which is obviously false. With this in mind if I entrust the task to keep conversational state in the underlying technology (such as a coockie or http session) I'm implementing a stateful service, but if all the necessary information (the context) are passed as parameters I'm implementing a stateless service. It should be noted that even if the passed parameter is an "identifier" of the conversational state (e.g. a ticket or a sessionId) we are still operating under a stateless service, because the conversation is stateless (the ticket is continually passed between client and server), and are the two endpoints to be, so to speak, "stateful".

    0 讨论(0)
  • 2020-11-28 18:43

    Stateless means there is no memory of the past. Every transaction is performed as if it were being done for the very first time.

    Stateful means that there is memory of the past. Previous transactions are remembered and may affect the current transaction.

    Stateless:

    // The state is derived by what is passed into the function
    
    function int addOne(int number)
    {
        return number + 1;
    }
    

    Stateful:

    // The state is maintained by the function
    
    private int _number = 0; //initially zero
    
    function int addOne()
    {
       _number++;
       return _number;
    }
    

    Refer from: https://softwareengineering.stackexchange.com/questions/101337/whats-the-difference-between-stateful-and-stateless

    0 讨论(0)
  • 2020-11-28 18:53

    Just to add on others' contributions....Another way is look at it from a web server and concurrency's point of view...

    HTTP is stateless in nature for a reason...In the case of a web server, being stateful means that it would have to remember a user's 'state' for their last connection, and /or keep an open connection to a requester. That would be very expensive and 'stressful' in an application with thousands of concurrent connections...

    Being stateless in this case has obvious efficient usage of resources...i.e support a connection in in a single instance of request and response...No overhead of keeping connections open and/or remember anything from the last request...

    0 讨论(0)
  • 2020-11-28 18:56

    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.

    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.

    0 讨论(0)
提交回复
热议问题