From 8325bde5bd0185752ef7df1c4c0440e14a2b4d98 Mon Sep 17 00:00:00 2001 From: Fendo181 Date: Thu, 5 Dec 2019 08:23:13 +0900 Subject: [PATCH 1/8] add README.md --- PrinciplesSystemDesign/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 PrinciplesSystemDesign/README.md diff --git a/PrinciplesSystemDesign/README.md b/PrinciplesSystemDesign/README.md new file mode 100644 index 0000000..77c31de --- /dev/null +++ b/PrinciplesSystemDesign/README.md @@ -0,0 +1,9 @@ +### 現場で役立つシステム設計の原則 + +本を読むとちょくちょくサンプルコードがJavaで紹介されて出てきます。 +これをPHPで写経して体現的に内容を学ぶ事を目的にしています。 + +### 参考資料 + +- [現場で役立つシステム設計の原則 - Fendo181](https://scrapbox.io/fendo181/%E7%8F%BE%E5%A0%B4%E3%81%A7%E5%BD%B9%E7%AB%8B%E3%81%A4%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E8%A8%AD%E8%A8%88%E3%81%AE%E5%8E%9F%E5%89%87) + From ed3c698bd9f7b6f23b17a881a10788b438a94f6a Mon Sep 17 00:00:00 2001 From: Fendo181 Date: Thu, 5 Dec 2019 08:36:12 +0900 Subject: [PATCH 2/8] =?UTF-8?q?p24=20=E9=80=81=E6=96=99=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=81=A8=E9=80=81=E6=96=99=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E3=81=86=E5=81=B4=E3=81=AE=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrinciplesSystemDesign/chap1/ShippingCost.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 PrinciplesSystemDesign/chap1/ShippingCost.php diff --git a/PrinciplesSystemDesign/chap1/ShippingCost.php b/PrinciplesSystemDesign/chap1/ShippingCost.php new file mode 100644 index 0000000..a281b04 --- /dev/null +++ b/PrinciplesSystemDesign/chap1/ShippingCost.php @@ -0,0 +1,30 @@ +basePrice = $basePrice; + } + + public function amount () :int{ + if( $this->basePrice < self::$minimumForFreeCost) return self::$cost; + return 0; + } +} + +function shippingCost(int $basePrice) :int { + $cost = new ShippingCost($basePrice); + return $cost->amount(); +} + +echo '送料の料金は'.shippingCost(1000); +echo '送料の料金は'.shippingCost(5000); + + + + From 3b3b0053bd903993617fddf501ce4357edce924a Mon Sep 17 00:00:00 2001 From: Fendo181 Date: Tue, 10 Dec 2019 00:35:51 +0900 Subject: [PATCH 3/8] =?UTF-8?q?p30=20add=20Quantity=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrinciplesSystemDesign/chap1/Quantity.php | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 PrinciplesSystemDesign/chap1/Quantity.php diff --git a/PrinciplesSystemDesign/chap1/Quantity.php b/PrinciplesSystemDesign/chap1/Quantity.php new file mode 100644 index 0000000..6211167 --- /dev/null +++ b/PrinciplesSystemDesign/chap1/Quantity.php @@ -0,0 +1,26 @@ + self::MAX) { + throw new Exception('100以上です'); + } + }catch (Exception $e ) { + echo '捕捉した例外: ', $e->getMessage(), "\n"; + } + + $this->value = $value; + } +} + +$quanty = new Quantity('200'); +echo $quanty->value; \ No newline at end of file From 9f529c2b7b4bd16d69f9580b0a557e87b3d311cc Mon Sep 17 00:00:00 2001 From: Fendo181 Date: Tue, 10 Dec 2019 10:05:05 +0900 Subject: [PATCH 4/8] =?UTF-8?q?addValue=E3=80=81canAdd=E3=80=81add?= =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E4=BD=9C=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=80=81=E5=80=A4=E3=81=8C=E4=BD=9C=E3=82=89=E3=82=8C?= =?UTF-8?q?=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=A7=E3=82=82=E5=88=B6=E9=99=90?= =?UTF-8?q?=E3=82=92=E8=A8=AD=E3=81=91=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrinciplesSystemDesign/chap1/Quantity.php | 34 +++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/PrinciplesSystemDesign/chap1/Quantity.php b/PrinciplesSystemDesign/chap1/Quantity.php index 6211167..5f77384 100644 --- a/PrinciplesSystemDesign/chap1/Quantity.php +++ b/PrinciplesSystemDesign/chap1/Quantity.php @@ -20,7 +20,37 @@ public function __construct(int $value) $this->value = $value; } + + private function addValue($other) { + $sum = $this->value + $other; + return $sum; + } + + + public function canAdd(int $other) :bool { + $added = self::addValue($other); + return $added <= self::MAX; + } + + public function add(int $other) { + + try{ + if(!$this->canAdd($other)) { + throw new Exception('合計が100を超えています'); + } + $added = $this->addValue($other); + // addすると新しいオブジェクトを呼び出す + return new Quantity($added); + + }catch (Exception $e){ + echo '捕捉した例外: ', $e->getMessage(), "\n"; + } + } } -$quanty = new Quantity('200'); -echo $quanty->value; \ No newline at end of file +// これで一回新しいオブジェクトを生成する +$quanty = new Quantity(10); +echo $quanty->value; + +// 新しいオブジェクトを生成する +$quanty->add(100); \ No newline at end of file From 87ef15ff499bcd6f5fa1b6c3bf42734708de0783 Mon Sep 17 00:00:00 2001 From: Fendo181 Date: Thu, 23 Jan 2020 09:55:09 +0900 Subject: [PATCH 5/8] =?UTF-8?q?p53=20=E3=82=AC=E3=83=BC=E3=83=89=E8=AA=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 早期リターンで条件記述の単純化作業となる --- PrinciplesSystemDesign/chap1/guard.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 PrinciplesSystemDesign/chap1/guard.php diff --git a/PrinciplesSystemDesign/chap1/guard.php b/PrinciplesSystemDesign/chap1/guard.php new file mode 100644 index 0000000..7e1ecf7 --- /dev/null +++ b/PrinciplesSystemDesign/chap1/guard.php @@ -0,0 +1,10 @@ += 18) return 'OK!'; + if($age > 15) return 'So So'; + if($age < 18) return 'NO!;'; +} + +$result = free(18); +echo $result; \ No newline at end of file From 40ff27c171e8cef7078ec5d96ac8080ce27c4d4f Mon Sep 17 00:00:00 2001 From: Fendo181 Date: Thu, 23 Jan 2020 10:00:22 +0900 Subject: [PATCH 6/8] =?UTF-8?q?=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=82=92=E7=A7=BB=E5=8B=95=E3=81=95=E3=81=9B?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrinciplesSystemDesign/{chap1 => chap2}/guard.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename PrinciplesSystemDesign/{chap1 => chap2}/guard.php (100%) diff --git a/PrinciplesSystemDesign/chap1/guard.php b/PrinciplesSystemDesign/chap2/guard.php similarity index 100% rename from PrinciplesSystemDesign/chap1/guard.php rename to PrinciplesSystemDesign/chap2/guard.php From c268fceb51b6e28ce2bc00c6dd4f902a499d7440 Mon Sep 17 00:00:00 2001 From: fendo181 Date: Tue, 4 Feb 2020 09:07:32 +0900 Subject: [PATCH 7/8] =?UTF-8?q?chap3=20p78=20=E3=83=87=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E3=82=92=E4=BF=9D=E6=8C=81=E3=81=99=E3=82=8B=E3=81=A0=E3=81=91?= =?UTF-8?q?=E3=81=AE=E6=82=AA=E3=81=84=E3=82=AF=E3=83=A9=E3=82=B9=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrinciplesSystemDesign/chap3/Person.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 PrinciplesSystemDesign/chap3/Person.php diff --git a/PrinciplesSystemDesign/chap3/Person.php b/PrinciplesSystemDesign/chap3/Person.php new file mode 100644 index 0000000..3c61055 --- /dev/null +++ b/PrinciplesSystemDesign/chap3/Person.php @@ -0,0 +1,17 @@ +firstName; + } + + private function getLastName() { + return$this->lastName; + } +} From 8eba1f7003f6a2041ee2356c5d0c7c77938a37f7 Mon Sep 17 00:00:00 2001 From: fendo181 Date: Tue, 4 Feb 2020 09:17:31 +0900 Subject: [PATCH 8/8] =?UTF-8?q?p79=20=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=81=AB=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF=E3=82=92=E3=82=82?= =?UTF-8?q?=E3=81=9F=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrinciplesSystemDesign/chap3/Person.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/PrinciplesSystemDesign/chap3/Person.php b/PrinciplesSystemDesign/chap3/Person.php index 3c61055..0864be9 100644 --- a/PrinciplesSystemDesign/chap3/Person.php +++ b/PrinciplesSystemDesign/chap3/Person.php @@ -1,17 +1,22 @@ firstName; + public function __construct($firstName,$lastName) + { + $this->firstName = $firstName; + $this->lastName = $lastName; } - private function getLastName() { - return$this->lastName; + public function fullName() { + return "MyName is {$this->firstName}.{$this->lastName}"; } + } + +$endo = new Person("Endo","Futoshi"); +echo $endo->fullName(); +