Design Patter by PHP[3]: Template Method
- Date
- 2006-10-18 (Wed)
- Category
- Design Pattern | Tech | php
日々是鍛錬。
第三回目は Template Method です。コードは前回に引き続き、Subversion のレポジトリ
をどうぞ。
今回の気づき
- 毎回思っていたけれど、PHP では名前空間の制約が厳しく、標準ライブラリに存在する関数と同じ名前の関数を定義できない。前2回分では、SPL で宣言されているクラス名と当たっていて、今回は標準関数の print だった。特に関数はなんとかしてもらいたい所ではある。だって内側から呼ぶのも $this つけなきゃ行けないわけだし、ambiguity はなさそうだけれども…
- println ってなかったっけ??
- 字数を数えるのにちょっと苦労した。以下 StringDisplay.php より
要するに、mb_strlen と strlen で数えてみて、一致してなかったらマルチバイト文字列と判断して、そうだったら、とりあえず2倍にしてある。ホントは private $is_mb とかつけて、printLine() を工夫すべきか、な。$this->width = mb_strlen($this->str); if ( $this->width != strlen($this->str) ) { $this->width = $this->width * 2; }少し正確に話すと、unicode では(ASCII 互換以外の文字列、いわゆるダブルバイトと呼ばれているもの)1文字3byte消費しているの(だよね?)で、『あ』の1文字で strlen では 3 という返り値、mb_strlen では 1 という返り値を得る。ま〜正確ではあるけど、使いやすくはないのかな〜- 追記 on March 2007: Unicode 、と一緒くたに語っていますが、これは正確じゃない。例えば(日本語の wikipedia によればほとんど使われていないらしいが) UTF-1 は 8-bit (≒ 1byte) コード。ここで語ろうとしている UTF-8 はマルチバイトで可変長 ( 1〜4 byte ) 。『あ』が 3byte だったのは“たまたま”。この実装は間違いですな。
実行結果は
$ php main.php
<<HHHHH>>
+-------------+
|Hello, World.|
|Hello, World.|
|Hello, World.|
|Hello, World.|
|Hello, World.|
+-------------+
+------------+
|こんにちは。|
|こんにちは。|
|こんにちは。|
|こんにちは。|
|こんにちは。|
+------------+
でした。
Comment:17
- coach outlet online:2011-08-19 (Fri) 05:50
-
Now can be the perfect time to choose a Coach Outlet Online. With fall getting best suited right here in numerous of weeks, something are on the way to acquire on clearance. But this appears to turn out to be the way in which by which you can appear throughout a little something at you Coach Handbags Outlet on sale. mentor utilizes the most significant best brilliant quality of factors to manufacture their products. We are the best Coach Purses Outlet agents.Welcome to buy in our online shop.More discount for you.
- Marlee:2011-08-19 (Fri) 13:54
-
I had no idea how to appraoch this before-now I'm locked and loaded.
- Cheap nike shox:2011-08-20 (Sat) 05:11
-
Our Nike Shox Outlet was the famous brand for men and women all over the world. Nike Shox have the great market as its good quality and reasonable price for many people. During you doing sports,Nike Shox Shoes Outlet give you superior comfortable and flexibility. The mesh lining above shoes and give you breathable wearing feeling. As a world famous sports brand,Nike Shox included Mens Nike Shox NZ and Womens Nike Shox NZ are very lightweight and durable. So you can choose these Nike Shox shoes by yourself and you will become the fashionable style. Cheap Nike Shox with excellent function will never let you down. Take action to select - uqzmee:2011-08-20 (Sat) 09:57
-
TYMS8b fdmlgtfxukzi
- Diablo III Gold:2011-09-16 (Fri) 04:50
-
chronograph now re interpretation not location etc the following five color recognize that the quality of oral and .
- Ugg Classic tall online:2011-09-18 (Sun) 21:46
-
The article in your blog reminds me some old memory .That is good .It gives me happy .I think we will have a harmonious talk.Do you agree?
- fake watches:2011-09-21 (Wed) 04:32
-
to the height The baggy clothesopen hair market to the one whomlike SwissReplicaStore and Baume Mercier offer.
- gxwatches:2011-09-22 (Thu) 21:43
-
best possible deal for your moneythe upcoming season many companiescomplicated mechanisms with the introduction of.
- wedding dress:2011-10-28 (Fri) 04:21
-
I like your article so that I read all of your articles in a day.Please continue and keep on writing excellent posts.
- Women's Parkas Montebello Parka MidGrey:2011-10-29 (Sat) 05:12
-
It’s worth to read it.Thank you for sharing. Women's Parkas Montebello Parka BlueTopaz will bring you a happy and free life when you are outside for skiing or playing. Women's Parkas Montebello Parka Brown are all in good quality, and the price of them is cheap and worthy for you to buy. Women's Parkas Montebello Parka MidGrey owns many different designs and materials, you can come and choose. http://www.canadagoose2011parka.org
- canada goose jackets:2011-11-02 (Wed) 06:30
-
This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.
- Office 2010:2011-11-16 (Wed) 20:09
-
No more switch Office 2007 from view to view in order Microsoft Office 2010 key to determine your availability.
- moncler jackets outlet:2011-11-21 (Mon) 05:22
-
Your lilies are so beautiful…and your doggie is so cute!! It sounds like he has a very nice friend, there!!
- cheap clothes:2011-11-29 (Tue) 22:35
-
Good article, well worth learning! Very good!
- Moncler Canada:2011-12-12 (Mon) 07:20
-
Should you have any questions, please do not hesitate to contact us.
- louis vuitton outlet:2011-12-14 (Wed) 01:24
-
New style louis vuitton outlet are all come with our online store,
100% authentic and 100% Satisfaction 2011 louis vuitton bags are accumulation cheapest price.
High quality guarantee with amazing low price from our louis vuitton outlet store online,
Come and just enjoy shopping here, what you see will the same as what you get,
buy cheap louis vuitton online now!
- North Face Denali For Girls:2011-12-23 (Fri) 21:01
-
outfits. Their very own Denali jackets are usually surely the original wide variety by most of your world's most reached outdoorsman ( blank ) snowboarders, ideal boarders, climbers.
Trackback:0
- TrackBack URL for this entry
- http://blogs.grf-design.com/mt/mt-tb.cgi/193
- Listed below are links to weblogs that reference
- Design Patter by PHP[3]: Template Method from The Croton