まず、イベント プログラミングまたは継承は、DCI と直交しています。継承なしで、イベント プログラミングを使用して (または使用せずに) DCI を実行できます。
JavaScript は、ある意味で DCI を実行するのに最適な言語の 1 つです。ほとんどの言語では、DCI に厳密に従うことに関していくつかの問題があります。JavaScript では、ファイナライザーがあれば問題を解決できますが、ファイナライザーがないということは、自分自身を意味するノイラープレート コードを「処分」する必要があることを意味します。
私は JavaScript で例を書きました。これをhttp://fullOO.infoにオンラインで公開します。Trygve、Jim、および私が一緒に作成した例と、他の人が同様に作成した例を見つけることができます。
fullOO.info は、DCI に詳しくなる場所への回答でもあります。また、DCI に関するディスカッションのために object-composition の Google グループに参加することもできます。
私が JS で書いた例は、正規の DCI 送金の例であり、興味深い部分 (ボイラープレート/ライブラリ コード以外のすべて) を以下に示します。
var moneyTransferContext = function(sourcePlayer, destinationPlayer, amount) {
var source = {
withdraw: function() {
var text = "Withdraw: " + amount;
this.log.push(text);
this.balance -= amount;
console.log("Balance: " + this.balance);
}
},
destination = {
deposit: function() {
var text = "Deposit: " + amount;
this.log.push(text);
this.balance += amount;
console.log("Balance: " + this.balance);
}
};
source = assign(source).to(sourcePlayer);
destination = assign(destination).to(destinationPlayer);
return {
transfer: function() {
source.withdraw();
destination.deposit();
return this;
}
};
},
sourceAccount = {
log: [],
balance: 100
},
destinationAccount = {
log: [],
balance: 0
};
moneyTransfer(sourceAccount, destinationAccount, 25).transfer().unbind();
残りはhttp://jsfiddle.net/K543c/17/で見ることができます