The Deficiency of the Object Model
// 身份和状态—-合并
As Java programmers, we are well versed in object-oriented programming(OOP). But the language has greatly infulenced the way we model OO apps. OOP did not quite turn out to be what Alan Kay had in mind when he coined the term. His vision(愿景) was primarily message passing, and he wanted to get rid of data. Somewhere along the way, OO languages started down the path of data hiding through Abstract Data Types(ADTs), binging data with procedure or combing state and behavior. This largely led us toward encapsulating and mutating state. In the process, we ended up merging the identity with state–the merging of the instance with its data.
This merging of identity and state snuck up on many Java programmers in a way that its consequences may not be obvious(悄然种入后果). When we traverse a pointer or reference to an instance, we land at the chunk of memory that holds its state. It feels natural to manipulate(操纵) the data at that location. The location represents the instance and what it contains. The combined identity and state worked out to be quite simple and easy to comprehend. However, this had some serious ramifications(分支) from the concurrency point of view.(从并发的角度就有问题了)
We will run into concurrency issues if, for example, we are running a report to print various details about a bank account–the number, current balance, transactions, minimum balance and so on. The reference(引用是入口) on hand is the gateway to the state that could change at any time. So, we are forced to lock other threads while we view the account. And the result is low concurrency. The problem did not start with the locking but with the merging of the account identity with its state.(身份和状态的绑定)
//OO 模拟现实世界还差点事
We were told that OO programming models the real word. Sadly, the real world does not quite behave as the current OO paradigm tries to model. In the real world, the state does not change, the identity does. We will discuss next how that is true.