标签:pat for most quick ems 模式 com quic rap
书上不全的代码,我自己补全的。
<?php /* The facade pattern is used when we want to simplify the complexities of large systems through a simpler interface. It does so by providing convenient methods for most common tasks, through a single wrapper class used by a client. */ class Product { private $qty = null; public function __construct($qty) { $this->qty = $qty; } public function getQty() { echo ‘Product_getQty<br/>‘; return $this->qty; } } class QuickOrderFacade { private $product = null; private $orderQty = null; public function __construct($product, $orderQty) { $this->product = $product; $this->orderQty = $orderQty; } public function generateOrder() { if ($this->qtyCheck()) { $this->addToCart(); $this->calculateShipping(); $this->applyDiscount(); $this->placeOrder(); } } private function addToCart() { echo ‘QuickOrderFacade_addToCart<br/>‘; } private function qtyCheck() { if ($this->product->getQty() > $this->orderQty) { return true; } else { return false; } } private function calculateShipping() { echo ‘QuickOrderFacade_calculateShipping<br/>‘; } private function applyDiscount() { echo ‘QuickOrderFacade_applyDiscount<br/>‘; } private function placeOrder() { echo ‘QuickOrderFacade_placeOrder<br/>‘; } } $order = new QuickOrderFacade(new Product(8), 6); $order->generateOrder(); ?>
标签:pat for most quick ems 模式 com quic rap
原文地址:https://www.cnblogs.com/aguncn/p/11182635.html