外观模式

<?php

/**
 * 外观模式又叫门面模式 作用就是减少子系统之间的耦合
 * 外部与一个子系统的通信必须通过一个统一的外观对象进行,为子系统中的一组接口提供一个一致的界面
 */


class File
{
    public function content()
    {
        return '获取文件内容' . PHP_EOL;
    }
}

class Crypt
{
    public function encrypt()
    {
        return '加密' . PHP_EOL;
    }
}

class Facade
{
    private $file;

    private $crypt;

    public function __construct()
    {
        $this->file = new File();
        $this->crypt = new Crypt();
    }

    public function encryptContent()
    {
        echo $this->file->content();
        echo $this->crypt->encrypt();
    }
}

$facade = new Facade();
$facade->encryptContent();
原文地址:https://www.cnblogs.com/cshaptx4869/p/12073215.html