development:software-architecture:design-patterns:facade
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
development:software-architecture:design-patterns:facade [2024/08/14 08:30] – tungnt | development:software-architecture:design-patterns:facade [2024/08/19 10:01] (current) – tungnt | ||
---|---|---|---|
Line 24: | Line 24: | ||
Facade giống như một bộ điều chỉnh đơn giản cho một số hệ thống phức tạp. Trong ví dụ này, Facade ẩn sự phức tạp của API YouTube và FFmpeg. | Facade giống như một bộ điều chỉnh đơn giản cho một số hệ thống phức tạp. Trong ví dụ này, Facade ẩn sự phức tạp của API YouTube và FFmpeg. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | **Ví dụ 1:** | ||
<file php> | <file php> | ||
Line 137: | Line 141: | ||
</ | </ | ||
- | ====== Tham khảo | + | **Ví dụ 2:** |
+ | |||
+ | <file php> | ||
+ | <?php | ||
+ | class Ink{ | ||
+ | public function check(){ | ||
+ | echo 'Đã check mực in' | ||
+ | } | ||
+ | } | ||
+ | class Paper { | ||
+ | public function check(){ | ||
+ | echo 'Đã check giấy' | ||
+ | } | ||
+ | public function getPaperForPrinting(){ | ||
+ | echo ' | ||
+ | } | ||
+ | }; | ||
+ | class PrinterEngine { | ||
+ | public function loadDocument($file){ | ||
+ | echo 'Tải tài liệu cần in' | ||
+ | } | ||
+ | public function formatDocumentData(){ | ||
+ | echo ' | ||
+ | } | ||
+ | |||
+ | public function warmUp(){ | ||
+ | echo 'warm up Engine' | ||
+ | } | ||
+ | public function prepareLaser(){ | ||
+ | echo ' | ||
+ | } | ||
+ | public function inkToPaper(){ | ||
+ | echo 'In mực lên giấy' | ||
+ | } | ||
+ | }; | ||
+ | class PrinterFacade{ | ||
+ | private static $instances; | ||
+ | protected function __construct() { } | ||
+ | protected function __clone() { } | ||
+ | |||
+ | public function __wakeup() | ||
+ | { | ||
+ | throw new \Exception(" | ||
+ | } | ||
+ | |||
+ | public static function getInstance() | ||
+ | { | ||
+ | if (!isset(self:: | ||
+ | self:: | ||
+ | } | ||
+ | return self:: | ||
+ | } | ||
+ | public function print($file){ | ||
+ | $ink = new Ink; | ||
+ | $paper = new Paper; | ||
+ | $printerEngine = new PrinterEngine; | ||
+ | $ink-> | ||
+ | $paper-> | ||
+ | $ink-> | ||
+ | $printerEngine-> | ||
+ | $printerEngine-> | ||
+ | $printerEngine-> | ||
+ | $printerEngine-> | ||
+ | $printerEngine-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | PrinterFacade:: | ||
+ | </ | ||
+ | |||
+ | ===== Tham khảo ===== | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
+ |
development/software-architecture/design-patterns/facade.1723624258.txt.gz · Last modified: 2024/08/14 08:30 by tungnt