Advanced ActionScript 3 with Design Patterns

Advanced ActionScript 3 with Design Patterns 』では、最初のパターンとして MVC パターンを紹介している。Moock 本の MVC パターンの解説に比べ、非常に簡潔にまとまっていると思う。Moock 本ではコードと説明が冗長で、設計は優れているものの実用的ではなかった。両者ともに、時計のアプリケーションをサンプルに扱っているので、読み比べると面白いだろう。

MVC パターンの肝とは何かを AA3WDP 本では以下のように解説している。

The most important key to the MVC pattern is that the model must be an independent object that does not have a reference to the view or controller.

例えば、FlashRSS リーダを設計する場合、MVC 分析を行うと以下のようになるだろう。

Model

  • Feed をロードし、保持する

View

  • Feed の内容をグラフィカルに表示する

Controller

  • Model から任意の Feed を取り出 し、View に渡す

Model となるクラスは、Feed をロードした後の処理は行わず、その時点でイベントを配信するだけでよい。