Chapter
[2] dealt with compound data as a means for constructing
computational objects that have several parts, in order to model
real-world objects that have several aspects. In that chapter we
introduced the discipline of data abstraction, according to which data
structures are specified in terms of constructors, which create data
objects, and selectors, which access the parts of compound data
objects. But we now know that there is another aspect of data that
chapter
[2] did not address. The desire to model systems composed of
objects that have changing state leads us to the need to modify
compound data objects, as well as to construct and select from them.
In order to model compound objects with changing state, we will design
data abstractions to include, in addition to selectors and
constructors, operations called
mutators, which modify data
objects. For instance, modeling a banking system requires us to
change account balances. Thus, a data structure for representing bank
accounts might admit an operation
第
[2] 章では、複数の部分を持つ計算オブジェクトを構築する手段として複合データを扱い、複数の側面を持つ現実世界のオブジェクトをモデル化しました。その章では、データ抽象の規律を導入しました。これは、データ構造をコンストラクタ(データオブジェクトを作成する操作)とセレクタ(複合データオブジェクトの部分にアクセスする操作)によって定義するというものです。しかし、第
[2] 章では扱わなかったデータのもう一つの側面があることがわかりました。変化する状態を持つオブジェクトで構成されたシステムをモデル化したいという要望から、複合データオブジェクトの構築や選択だけでなく、それらを変更する必要性が生じます。変化する状態を持つ複合オブジェクトをモデル化するために、セレクタやコンストラクタに加えて、データオブジェクトを変更する
ミューテータと呼ばれる操作をデータ抽象に含めるよう設計します。たとえば、銀行システムのモデル化では口座残高を変更する必要があります。したがって、銀行口座を表現するデータ構造は、次のような操作を受け付けるかもしれません。
that changes the balance of the designated account to the designated
new value. Data objects for which mutators are defined are known as
mutable data objects.