Stateless vs Stateful

前端 未结 8 1353
暖寄归人
暖寄归人 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: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

提交回复
热议问题