ãã®è¨äºã«ã¤ãã¦
ãWillgate Advent Calendar 2018ã11 æ¥ç®ã®è¨äºã§ãã
è¨äºãæ稿ãããæ¥ä»ã¯æ°ã«ãã¦ã¯ãããªãããããï¼
ãã£ãã
ããã 2 ã¶æåã«ä¸æ¸ãã«ãªã£ã¦ããè¨äºããã£ãã®ã§æãè¿ãã
ãã®è¨äºãæ¸ãå§ããããã® twitter ã®ã¿ã¤ã ã©ã¤ã³ã«ãããªãã¤ã¼ããæµãã¦ãã¾ããã
ã¨ã³ãã°ãæ罪ãããããªæèããããæ°ã«å ¥ããªããå人ã®æ³¨æåã«ä¾åããã®ã¯å·¥å¦çãããªãã罪ã¯ãã°ãçºçããããè¨è¨ã«ããã¨èããã®ãã¨ã³ã¸ãã¢ãããªãã®? ã£ã¦æããåã ã®ãã°ã«å¯¾ãã¦è¿·æ被ã£ãã¨æãã®ã¯ã¨ã³ãã¦ã¼ã¶ã¼è¦ç¹ãããªã人ã ã¨æã
— ç°ä¸ã²ãã¦ã (@tanakahisateru) 2018å¹´10æ2æ¥
ç§ãããã«è¿ãèãããã£ã¨æ±ãã¦ãã¦ããã®ã§ãå¼ç¨ãªãã¤ã¼ã + ã³ã¡ã³ãããã«ã¯ãããã¾ããã§ããã
æ¬å½ã«ããã
— ããããã (@okashoi) 2018å¹´10æ2æ¥
ãã°ããªãããã«ãæ°ãã¤ãã¦ãä½ãããããªãããã°ãä½å°ãç¡ãããã«ãèãã¦ãä½ãã
ä¼¼ã¦ããããã§ãå ¨ãéãã https://t.co/sr98ZYiL7C
ä»åã¯ããã®ããã°ããªãããã«ãæ°ãã¤ãã¦ãä½ãã®ã§ã¯ãªãããã°ãä½å°ãç¡ãããã«ãèãã¦ãä½ããã¨ããèãæ¹ã«ã¤ãã¦ãããå°ãæ·±æããã¦ã¿ã¾ãã
èæ¯
ã½ããã¦ã§ã¢ã«éãããåºãã¨ã³ã¸ãã¢ãªã³ã°ï¼å·¥å¦ï¼ã®ä¸çã«ã¯ããã¼ã«ãã«ã¼ããã¨ããèãæ¹ãããã¾ãã
ç´è¨³ããã¨ã馬鹿é¤ããã¨èº«ãèãç¡ãè¨ãæ¹ã§ããããã¨ã¿çç£æ¹å¼ã®æèã§ã¯ããã«ã¨ã±ãã¨å¼ã°ãããã®ã¾ã¾ "Poka-yoke" ã¨ããè±åèªã«ããªã£ã¦ãã¾ã*1ã
ããã¯ããªãã¡ã人éã¯ãã¹ï¼ãã«ï¼ããããã®ã¨ããåæã®ãã¨ãä»çµã¿ã«ãã£ã¦æ£ããæåã»å®å ¨ãæ ä¿ããããã¨ããèãæ¹ã§ã代表ä¾ã¨ãã¦ã¯ãï¼çæãå·»ãè¾¼ã¾ããªãããã«ï¼ä¸¡æã§ã¹ã¤ãããæ¼ããªãã¨åä½ããªãå·¥ä½æ©æ¢°ããªã©ãæãããã¾ãã
ç¾å¨ã®ç§ã®ä»äºã¯ããã¹ã«ãã£ã¦äººã®å½ã失ããããæªæãããããããããªç°å¢ã§ããã¾ãããããã°ãçã¿åºãã¦ãã¾ãã°ä½ãããã®æ害*2ã«ã¤ãªãããã¨ã«ã¯å¤ããã¾ããã
ãã®èãããç§ã¯ãã©ãããããã°ãå ¥ãè¾¼ãä½å°ããªãããã«ä½ããã®ããã¨ãããã¨ã«å¼·ãé¢å¿ãæ±ãç¶ãã¦ãã¾ããã
å ·ä½ä¾
ã©ããªã«æ°ãä»ãã¦ã人éã®æ³¨æåã«ã¯éçãããã¾ããå è¿°ã®éãã人éã¯ãã¹ããããã®ããªã®ã§ãã
ä¾ãã°ã注æãã¨ãããã¼ã¿ãã次ã®ããã«ï¼é£æ³ï¼é åã使ã£ã¦è¡¨ç¾ããã¨ãã¾ãã
<?php $order = [ 'order_id' => 1, 'client_id' => 1, 'ordered_at' => '2018-10-04 00:00:00', 'products' => [ [ 'product_id' => 1, 'amount' => 20, ], [ 'product_id' => 2, 'amount' => 10, ], ], ];
ãã®ããã«è¡¨ç¾ããã¨ã次ã®ãããªããã¹ãããä½å°ããçãã¦ãã¾ãã¾ãã
å±æ§ã®æ¼ã
<?php $order = [ 'order_id' => 1, // client_id ãå¿ãã¦ãã 'ordered_at' => '2018-10-04 00:00:00', 'products' => [ [ 'product_id' => 1, 'amount' => 20, ], [ 'product_id' => 2, 'amount' => 10, ], ],
å±æ§åã® typo
<?php $order = [ 'order_id' => 1, 'cilent_id' => 1, // client_id ã typo ãã¦ãã 'ordered_at' => '2018-10-04 00:00:00', 'products' => [ [ 'product_id' => 1, 'amount' => 20, ], [ 'product_id' => 2, 'amount' => 10, ], ], ];
éãå±æ§ã®å¤ãä»£å ¥
<?php $order = [ 'order_id' => 1, 'ordered_at' => 1, 'client_id' => '2018-10-04 00:00:00', // client_id 㨠ordered_at ã®å¤ãéã«æå®ãã¦ãã 'products' => [ [ 'product_id' => 1, 'amount' => 20, ], [ 'product_id' => 2, 'amount' => 10, ], ], ];
ä¸è¨ã¯ãã¹ã¦ PHP ã®ææ³ä¸ã¯æ£ããã®ã§ããã«ã¨ã©ã¼ã«ãªãããæ¤ç¥ãé ãã¾ãã
ã¾ãã注æããååã®ç·æ°ãè¨ç®ããã«ã¯ foreach ãªã©ã使ã£ã¦ã«ã¼ããæ¸ããã¨ã«ãªãã¾ãã ããã«ãã¦ã³ã¼ãã®ãã¹ãã¯æ·±ããªããè¦éããæªããªããã¡ã§ãã
ã§ã¯é åã§ã¯ãªãã¯ã©ã¹ã使ã£ã¦ã注æãããã®å±æ§ã表ç¾ãã¦ã¿ãã¨ã©ããªãã§ãããã
ä¸è¨ã¯ããã¾ã§ä¸ä¾ã§ãã
<?php class OrderId { protected $value; public function __construct(int $value) { $this->value = $value; } } class ClientId { protected $value; public function __construct(int $value) { $this->value = $value; } } class Order { protected $id; protected $clientId; protected $orderedAt; protected $products; public function __construct(OrderId $id, ClientId $clientId, \DateTime $orderedAt, array $products) { $this->id = $id; $this->clientId = $clientId; $this->orderedAt = $orderedAt; $this->products = $products; } public function calculateTotalProductAmount(): int { $amount = 0; foreach ($this->products as $product) { $amount += $product['amount']; } return $amount; } }
ãã®ããã«ããã°ãé åã§è¡¨ç¾ãã¦ããã¨ãã«åå¨ãã¦ããããã¹ããä½å°ããç¡ããªãã¾ãããªã«ããããã¹ãããã°å³åº§ã«æ§æã¨ã©ã¼ã¨ãã¦æ¤ç¥ãããã¨ãã§ãã¾ãã
ã¾ãã注æããååã®ç·æ°ã®è¨ç®ãã¸ãã¯ãã¡ã½ããå ã«éããããã®ã§ã³ã¼ãã®è¦éããè¯ããªãã¾ãã
ããã«ããã®ãã¼ã¿ãä½ãªã®ããã¨ããæ å ±ããé åã§è¡¨ç¾ãã¦ããã¨ãã«ã¯ãè¾ããã¦å¤æ°åããæ¨æ¸¬ã§ããããããã ã£ããã®ããã¯ã©ã¹ï¼åï¼ãæã¤ãã¨ã§æ確ã«ãªãã¨ããã¡ãªãããããã¾ãã
ãã®ããã«ãã¦è¨è¨ã®åã«ãã£ã¦ããã°ããããã¨ãé£ããã§ãããã¨ãã風ã«èããããããã§ãã
ä½è«
ããã¯ç§è¦ã«ãªãã¾ããããã¹ãããä½å°ãã®ããããã°ã©ã ãæ¸ãã®ã¯ãããã°ã©ãã³ã°åå¿è ã ãã§ãªããé ã®è¯ã人*3ã®å ´åãå¤ãæ°ããã¾ãã
é ãè¯ãã®ã§ãã®äººã¯ãã®æ¹æ³ã§ããã¹ãããã¨ãããã¾ããããªã®ã§ãã®æ¹æ³ã«çåãæã¤æ©ä¼ãç¡ãã®ã ã¨æãã¾ãã
ããããããªã³ã¼ããã²ã¨ãã³ãæ®éã®äººãã«å¼ãç¶ãããã°ãããã¯ãã£ã¨æ²åã®å§ã¾ãã§ãããã
ã ããããã°ãä½å°ãç¡ãããã«ãèãã¦ãä½ããã¨ããèãæ¹ãåºãã¦ãããããã¨æãã®ã§ãã
ã§ããæè¿ã«ãªã£ã¦ããã®èãæ¹ã«ã¤ãã¦ããã«æããã¨ãçã¾ãã¦ãã¾ããã
ããã¯ã¡ãã£ã¨é·ããªããããªã®ã§å¥ã¨ã³ããªã«æ¸ããã¨ã«ãã¾ãã