デザインパターン
かなり消化不足だけどとりあえず残しておく。結城センセイの本にあるMediatorパターンが一番わかりやすそうだけれどJavaで実装はしたことないからJavaScriptとブラウザを使おうかどうか思案中。。 name = $name; } public function getName(){ return $this-…
use strict; use warnings; { package Database; use strict; use warnings; sub new {die;} sub select_username_from_db_where_mailaddr_equal { my ($class, $mailaddr) = @_; if($mailaddr eq 'admin@hoge.com'){ return "Watasi wa kanrinin"; } else {…
再帰の部分で苦しむ。シーケンス図を描くことで(本にも載っている)掴みやすくはなる。ShallowCopyとは何なのかDeepCopyとは何なのかとかが少し理解できていないと苦しい。なぜShallowCopyなのかもしくはDeepCopyなのかが分っていれば楽なのだろうけれどそれ…
理解の足らない部分が見えてきたけれど、兎に角23パターン全部やってみる。 use strict; use warnings; { package Display; use strict; use warnings; sub getColumns {die;} sub getRows {die;} sub getRowText {die;} sub show { my ($self, ) = @_; for(…
やはり再帰に苦手意識がある。以前schemeを少しかじってみたのが救いで、そこいらをやりこめば苦手意識も消えるだろうと思っている。 use strict; use warnings; { package Entry; use strict; use warnings; sub add {} sub printList {die;} sub toString …
PHP5.1.6環境でPHP4スタイルで書きました。PHP5からは組み込みのIteratorがあるらしいけれど、基本的なことを学ぶのが目的なのでなるべくそういった便利さは省く。
久々のエントリ。もう一つは時間の都合で移し変えず、同じstrategyで勝負しています。 use strict; use warnings; { package Hand; use strict; use warnings; my $GUU = 0; my $CHO = 1; my $PAA = 2; my $hand = [ Hand->new($GUU), Hand->new($CHO), Hand…
createReader($filename); return $reader; } private function createReader($filename){ if($filename == 'foo.txt'){ return new FooReader($filename); } else if($filename == 'bar.txt'){ return new BarReader($filename); } else…
use strict; use warnings; { package Display; use strict; use warnings; sub new { my ($class, $impl, ) = @_; my $self = { impl => $impl, }; return bless $self, $class; } sub open { $_[0]->{impl}->rawOpen(); } sub print { $_[0]->{impl}->rawP…
use strict; use warnings; { package Director; use strict; use warnings; sub new { my ($class, $builder) = @_; my $self = { builder => $builder, }; return bless $self, $class; } sub construct { my $self = shift; $self->{builder}->makeTitle(…
use strict; use warnings; { package Interface::Product; use strict; use warnings; sub use { die; } sub createClone{ die; } } { package Manager; use strict; use warnings; use Data::Dumper; sub new { my ($class,) = @_; my $self = {}; return …
最後の方は疲れてきてIteratorを使うべき所を横着している。きちんとクラス図を書いて整理するとなるほどと思う。Compositeパターンも絡んでくるとやや面倒。is-aとhas-aをきちんと区別できるかどうか。フォルダとファイルの構造と同じ。フォルダの中にフォ…
手作りのabstract classを書いてみると、新鮮な発見もある感じ。 use strict; use warnings; { package Abstract::AbstractDisplay; use strict; use warnings; sub new { my $class = shift; my $self = {}; return bless $self, $class; } sub open { die;…
以下を参考にさせてもらいました。 http://d.hatena.ne.jp/hiboma/20060510/1147190899 $singleton変数はprivateなスコープになる。この辺りを追求するには以下の本がなかなか参考になりました。わりとお堅い感じの本で、途中で挫折しかかりましたが。。 use…
各クラスの意味や必要性がわかりにくい、といった場合は実装に近い側から読んでいくと掴める場合がよくある。今回は「工場で作ったカードを使う」ということが簡単に読み取れる。 コーディングもIDcardFactoryのnewから書き始めて、必要な部分を書いて、最後…
use strict; use warnings; { package Abstract::Print; use strict; use warnings; sub printWeak { die ""; } sub printStrong { die ""; } } { package PrintBanner; use strict; use warnings; use Data::Dumper; our @ISA = qw/Abstract::Print/; sub n…
use strict; use warnings; { package Banner; use strict; use warnings; sub new { my ($class, $string) = @_; my $self = { string => $string, }; return bless $self, $class; } sub showWithParen { my $self = shift; print "(".$self->{string}.")"…
use strict; use warnings; { package Aggregate; use strict; use warnings; sub iterator { die "use OverRide"; } } { package Iterator; use strict; use warnings; sub hasNext { die "use OrverRide"; } sub next { die "use OverRide"; } } { package…
GoF本の23パターン AbstractFactory Perl Builder Perl FactoryMethod Perl PHP5 Prototype Perl Singleton Perl Adaptoer Perl Perl(委譲を利用) Bridge Perl Composite Perl Decorator Perl Facade Perl Flyweight Proxy Chain of Responsibility PHP4,5 C…
ヴァージョン5で。 だらだらと分岐を書くのはいいかげんやめようと。 set(new NotHoge())->set(new NotMoge()); $rs = $chk->execute($str); print "<pre>"; print_r($chk); print_r($rs); //---------------------------------- class InpChk{ var $list; functi</pre>…
メモ程度に。。 file = $file; } public function showPatternA(){ print $this->file."をPatternA表示"; } public function showPatternB(){ print $this->file."をPatternB表示"; } public function showPatternC(){ print $this->file."をPatternC表示"; …