Reactive Programming 2.1 Functions and State

Source: Internet
Author: User

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.