concept account in category c#

appears as: ccount, account, n account, accounts, An account, ccounts
Functional Programming in C#: How to write better C# code

This is an excerpt from Manning's book Functional Programming in C#: How to write better C# code.

This not only clearly conveys the fact that a value for Name may not be available; it causes GreetingFor to no longer compile. GreetingFor, and any other code that was accessing the Name property, will have to be modified to take into account the possibility of the value being absent. For example, you might modify it like so:

Let’s see how this would play out in our banking scenario. We need to ensure that when different transactions (debits, credits, transfers) happen concurrently, they don’t leave the account in an invalid state. Does this mean we need to synchronize access to the account data? Not necessarily! Let’s see what happens if we don’t take any special measures with respect to concurrency.

Imagine an account with a balance of 1,000. An automated direct debit payment occurs, causing 800 to be debited from the account. Concurrently, a transfer of 200 is requested, so that the amount of 200 is also debited. If we use the event-sourced approach shown so far in this book, we get the following result:

Listing 15.7. Sequential processing of commands that affect an account

Each instance of AccountProcess internally holds an agent, so all commands that affect the account can be processed sequentially. Let’s look at the body of the agent: first, we calculate the result of the command, given the command and the current state. This is done using pure, static functions only.

Before you read on, go through the implementation again. Can you see any problems with this approach? Let’s see: loading the account state from the DB is done within the agent body; is that warranted? This means that reading the state for account x will block another thread that’s interested in account y. That’s certainly suboptimal!