Stateful Objects A Stateful object
One normally describes the world as a set of objects, some of which has
State This changes over the course of time.
An object with a state if it behavior is influenced by it history.
An object is stateful if its behavior is influenced by history
EXAMPLE:A bank account had a state, because the answer to the question
"Can I withdraw CHF?"
May vary over the course of the lifetime of the
An account is stateful because of the question: Can I take 100 dollars? May not be the same answer at different times.
2. Objects with Var are not necessarily stateful
def Cons[t] (hd:t, tl: = = stream[t]) = new Stream[t] {def head = HD private var tlopt:option[stream[t]] = None def Tail:t = tlopt Match {case Some (x) + x Case None = + tlopt = Some (TL); tail}}
Each call to tail and head returns the same result.
3. Objects without var are not necessarily stateless
Class Bankaccountproxy (ba:bankaccount) {def deposit (amount:int): Unit = Ba.deposit (amount) def withdraw (Amount:int): Int = Ba.withdraw (amount)}
Reactive Programming 2.1 Functions and State