To implement the scenario for this section, you will add a method similar to Perform, named StatefulPerform, which uses class member variables to set account numbers. Thus, MoveMoney becomes a stateful object when StatefulPerform is called.
Click here to see the StatefulPerform method
The code for StatefulPerform calls the Perform method. The methods differ in how the account numbers are set. Class member variables for each account must be set before calling StatefulPerform, whereas Perform passes the account numbers by value through function parameters.
When you click the MoveMoney option in the Sample Bank client, it calls the following code to initialize the function:
lRet = obj.Perform(CLng(PrimeAcct), lSecondAcct, CLng(Amount), TranType, Res)
When you click the Stateful MoveMoney option, the Sample Bank client calls the following code to initialize the function:
obj.PrimeAccountNo = PrimeAcct
obj.SecondAccountNo = lSecondAcct
lRet = obj.StatefulPerform(CLng(Amount), TranType, Res)
The PrimeAccountNo and SecondAccountNo properties are actually separate class member variables on the MoveMoney object. Note that the PrimeAccountNo and SecondAccountNo properties aren't accessed through the Shared Property Manager properties; the MoveMoney object controls getting and setting the account number values, thus making the MoveMoney object stateful.
Run the Bank client with the MoveMoney option. Then run it again with the Stateful MoveMoney option. You should notice that the stateless version is slightly faster. Try running multiple Bank clients with concurrent transactions. You should notice that the stateless version performs significantly better. The next section explains why.
Transactions, Deactivating Objects, Context Objects, Stateful Components