JavaScriptデザインパターンってなんだかたいそうなものに考えられがちだけど、実は、そこかしこのライブラリや仕様に取り込まれていることが多い。「デザインパターン分からん」とか「で、どうやって使うのよ」と悶々としている人には、「どういうところで使わているのか」を知っておけばイメージも沸きやすいし、意外にたいしたことないんだな、ということが分かるんじゃないだろうか。そこで、JavaScript やその周辺の技術で、デザインパターンがどのように使われているかを紹介してみることにする。ここでは、GoF本の順番に沿って、以下の11個のパターンを取り上げる。生成に関するパターン Factory MethodAbstract FactoryBuilderPrototypeSingleton構造に関するパターン AdapterComposite振る舞いに関するパターン Chain Of Respon
CakePHPを使ったMVC設計のベストプラクティス 個人的にはCakePHPはあまり好きではないのですが、CakePHP開発メンバーによるMVCデザインの記事 (CakePHP のおいしい食べ方)で紹介されていたBest Practices in MVC Design with CakePHP (php|architect’s C7Y)はMVCフレームワーク利用者にとってとても有用な情報だったので、訳してみました(php|architectの方には翻訳許可を頂いています)。 この記事を読んでドメインモデルに興味を持った方は、エンタープライズ アプリケーションアーキテクチャパターン(PoEAA)やDomain-Driven Design: Tackling Complexity in the Heart of Softwareに手を出してみるのもいいかも。他に、InfoQにユーザー登録すれ
Download the Code Examples The code examples are available as a Zip file (80 KB). About the Book As a web developer, you'll already know that JavaScript is a powerful language, allowing you to add an impressive array of dynamic functionality to otherwise static web sites. But there is more power waiting to be unlocked—JavaScript is capable of full object-oriented capabilities, and by applying OOP
はてブコメントにて、「シリーズ化して欲しい」とあったので、もう少し書いてみます。 今回紹介するパターンは、Controllerパターン。 たぶん、デザパタ(GoFとかのヤツ)ではControllerパターンなんてものは存在しないのですが、よく見掛けるパターンなので紹介します。 よくあるControllerパターンは、FrontControllerパターンを使ったデータ遷移パターンですが、今回僕が紹介するパターンはCommandController(これもGoFとかのパターンにたぶん無いので勝手に命名)です。 何か実行したいCommandについて、Controllerが適切に実装を振り分けその後のActionを実行するためのパターンです。 よくある実装 例えば、以下にCommandインタフェースを実装した複数のクラスがあり、そのCommandによって、実行するActionを振り分けるCo
ITT-WEB - XOOPSCubeにおけるDelegateとは何か?というエントリが上がっているので、ちょっとだけDelegateについて触れてみたいです。 Delegateとは、そのままの意味で「委譲」を示します。(集約ではないです) とある処理をそれまで行っていたクラスから、ちがうクラスに対して処理を行ってもらうようにします。 Delegateと書くとちょっと堅苦しいですが、proxyやTemplate Methodに近い存在です。 Delegateは慣れてくると色々なパターンに適用しやすい便利なパターンなので、是非身に着けたいものです。 以下にファイルのデータを書き込む処理の例を示します。 class DataWriter { public function write(Data $data){ $file = new File($data->getPath()); if(
PHPのクラスに備わっているstaticはJava(Servlet)のそれとは違いHTTPのリクエストが完了すると破棄されてしまいます。 そのためstaticフィールドを使ったシングルトンの実装を行ったとしてもリクエストがある度にインスタンスが生成され独立したプロセスから同一のインスタンスにアクセスすることは不可能です。 そこで今回memcachedを利用しPHPの各プロセスから同一のインスタンスを参照できるようにしてみたいと思います。 といってもシリアライズさせているので厳密には別のインスタンスになりますが…。 ちなみにmemcachedとはオブジェクトをメモリにキャッシュさせるPHPとは独立したサーバプログラムです。 利用できる言語はPHPだけに限らずPerl、Ruby、Java、Pythonなどにも対応しています。 インストールは./configure && make &
経験的にこのようにした方がよいと思った点についての記録です。 仕事で大規模(2000クラス超)かつ製品寿命がながいパッケージソフトを作っていた関係で、 ちょっとした設計の間違いが、 あとあとで大変な苦労する羽目になったりすることを経験してきました。 このような規模が大きいアプリケーションを作ることはなかなかないかもしれませんが、 なにかの参考になれば、と思います。 継承する前に委譲を検討する Singleton パターンを使うときの注意 Template Method パターンを使うときの注意 クラス間の依存に関する注意 クラスの粒度 Singleton の問題を回避できるか? 継承する前に委譲を検討する 継承はスーパークラスの仕様をよく理解しておかないと、 バグを作りこみやすいので十分注意する必要があります。 メソッドのオーバーライドをするときも、 public void foo(){
突然ですが、きっとあなたも使っているデザインパターンシリーズ 何気なく書いていたあのクラスが無意識的にNullObjectパターンやHook Operationパターンを適用していることがここ最近多い気がしませんか? 僕の場合はS2Daoを通して見付けた(身に着けた)ものが多いんですが、今回はそのS2Daoより、簡単に書けるHook OperationパターンとNullObjectパターンをPHP5で書いてみます。 Hook Operationパターン 「Hook Operationパターン」にも書かれていますが、あるクラスの処理の前と後ろに、別の処理を実行したいことがあります。 AOPとか特別なことはせずに、あるクラスの前処理と後処理を呼び出します。 あるクラスの処理を「Process」クラスの「execute」処理とし、別の処理(前・後)は「Hook」インタフェースを実装するクラス
「DI(依存性注入)からどこへ行こうか その1」において: DI(依存性注入)については、雑誌や書籍で随分紹介されているので、そういうのを見てください。 こんなこと[注:DI化]して何がうれしいかって? それは、ファウラー先生とかその他エライ人とかエラクない人とかに聞いてください。 と書きましたが、DI(Dependency Injection; 依存性注入)そのものについても説明を試みてみましょう。具体的なサンプルを使うことにします。そのため、サンプルの説明が長くなってしまうのが困ったことですが、まー、単なる能書きよりはサンプルがあったほうがいいでしょ。 内容: サンプルはテンプレート処理系 レクサー(字句処理系) レクサーをインターフェース経由で使う サービス・ロケーター 依存性が消えてない! DI(依存性注入)登場 DIが、かつてIoC(制御の逆転)と呼ばれていた理由 ●サンプルはテ
『デザインパターン』 うんちくできると、かっこよさそうだよね~。でもあんな分厚い本読んでもピンとこないし、だいたいオブジェクト指向ってなに?なにが便利なのかよく分からんのだけど。いいじゃんなんでも。できればいいんだよ、できれば。 な~んて、思っていても、なんとなく オブジェクト指向が気になっている システム開発者は、多いのではないでしょうか?かくいう 私もそんな者の一人でした。 しかし、これだけ もてはやされているオブジェクト指向です。 なんか、便利なはずです。 そこで、私は、GOFのデザインパターン[1]を、できるだけシンプルに表現した、小さな小さなプログラム ~デザインパターンの骸骨たち~ を作ってみました。骸骨達 を骨の髄までしゃぶり尽くつくすせば、オブジェクト指向の真髄まで味わうことができるかも。!? 『デザインパターンの骸骨たち(RE-BONE)』 では、内容を大幅に見直し、Ja
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く