Design Patter by PHP[2]: Adapter
- Date
- 2006-10-16 (Mon)
- Category
- Design Pattern | Tech | php
前回の イテレータ パターン からはだいぶ時間が空いてしまいました。本を友人に貸していたからなんですが、まぁ言い訳はこのくらいにして。
未だ Chpater 2: Adapter Pattern です。今回からは(昨日から運用開始した)Subversion を使ってレポジトリを公開〜。まだ非常に稚拙なコードですが、興味のある人は、
をどうぞ。
今回の気づき
- Java の super() は PHP で parent:: となる。
- PHP4 では class 名と同じ function がコンストラクタに、いわゆる Java と同じ形式だけだったのに、PHP5 から Object に __construct() という特殊関数ができて、誰が使うんだろーなー、と正直思っていたけれど、なるほど確かに parent::__construct() を呼ぶのに、統一的かつ合理的にするには __construct() を使うべきだと思いました。ちなみにマニュアルにはこう書いてあります。
For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named __construct() which was used for different semantics.
実際実験してみましたが、__construct() を class 宣言の中に含めなくても parent::__construct() で呼び出すことができています。
- PHP4 では class 名と同じ function がコンストラクタに、いわゆる Java と同じ形式だけだったのに、PHP5 から Object に __construct() という特殊関数ができて、誰が使うんだろーなー、と正直思っていたけれど、なるほど確かに parent::__construct() を呼ぶのに、統一的かつ合理的にするには __construct() を使うべきだと思いました。ちなみにマニュアルにはこう書いてあります。
- PHP とは関係なく、svnX の使い勝手の問題なんですが、Working Copies ウィンドウから開けるところで、Update ボタンを押すと、"Are you sure you want to update this working copy to the latest revision?" って聞いてくれるのだけれども、Yes を押すと、どれが変わるとかは言ってくれないで、黙ってアップデートされてるのがすこし気になった。
Comment:0
Trackback:0
- TrackBack URL for this entry
- http://blogs.grf-design.com/mt/mt-tb.cgi/192
- Listed below are links to weblogs that reference
- Design Patter by PHP[2]: Adapter from The Croton