TungNT (Blue)

tungnt.blue@gmail.com

User Tools

Site Tools


development:software-architecture:design-patterns:facade

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
development:software-architecture:design-patterns:facade [2024/08/14 08:30] tungntdevelopment: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.
 +
 +{{ :development:software-architecture:design-patterns:facade-structure.png |}}
 +
 +**Ví dụ 1:**
  
 <file php> <file php>
Line 137: Line 141:
 </file> </file>
  
-====== Tham khảo ======+**Ví dụ 2:** 
 + 
 +<file php> 
 +<?php 
 +class Ink{ 
 +    public function check(){ 
 +        echo 'Đã check mực in'.PHP_EOL; 
 +    } 
 +
 +class Paper { 
 +    public function check(){ 
 +        echo 'Đã check giấy'.PHP_EOL; 
 +    } 
 +    public function getPaperForPrinting(){ 
 +        echo 'Chuẩn bị giấy để in'.PHP_EOL; 
 +    } 
 +}; 
 +class PrinterEngine { 
 +    public function loadDocument($file){ 
 +        echo 'Tải tài liệu cần in'.PHP_EOL; 
 +    } 
 +    public function formatDocumentData(){ 
 +        echo 'Format dữ liệu'.PHP_EOL; 
 +    } 
 + 
 +    public function warmUp(){ 
 +        echo 'warm up Engine'.PHP_EOL; 
 +    } 
 +    public function prepareLaser(){ 
 +        echo 'Chuẩn bị Laser'.PHP_EOL; 
 +    } 
 +    public function inkToPaper(){ 
 +        echo 'In mực lên giấy'.PHP_EOL; 
 +    } 
 +}; 
 +class PrinterFacade{ 
 +    private static $instances; 
 +    protected function __construct() { } 
 +    protected function __clone() { } 
 + 
 +    public function __wakeup() 
 +    { 
 +        throw new \Exception("Cannot unserialize singleton"); 
 +    } 
 + 
 +    public static function getInstance() 
 +    { 
 +        if (!isset(self::$instances)) { 
 +            self::$instances new self; 
 +        } 
 +        return self::$instances; 
 +    } 
 +    public function print($file){ 
 +        $ink = new Ink; 
 +        $paper = new Paper; 
 +        $printerEngine = new PrinterEngine; 
 +        $ink->check(); 
 +        $paper->check(); 
 +        $ink->check(); 
 +        $printerEngine->loadDocument($file); 
 +        $printerEngine->formatDocumentData(); 
 +        $printerEngine->warmUp(); 
 +        $printerEngine->prepareLaser(); 
 +        $printerEngine->inkToPaper(); 
 +    } 
 +
 + 
 + 
 +PrinterFacade::getInstance()->print('Tài liệu mật'); 
 +</file> 
 + 
 +===== Tham khảo =====
  
   * https://refactoring.guru/design-patterns/facade   * https://refactoring.guru/design-patterns/facade
   * https://www.youtube.com/watch?v=zK_sNkfzugs   * https://www.youtube.com/watch?v=zK_sNkfzugs
   * [[https://www.freecodecamp.org/news/how-to-use-facades-in-laravel/|How to Use Facades in Laravel]]   * [[https://www.freecodecamp.org/news/how-to-use-facades-in-laravel/|How to Use Facades in Laravel]]
 +  * [[https://blog.tda.company/tim-hieu-facade-design-pattern-trong-laravel|Tìm hiểu Facade Design Pattern trong Laravel]]
 +
development/software-architecture/design-patterns/facade.1723624258.txt.gz · Last modified: 2024/08/14 08:30 by tungnt

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki