Home > Backend Development > PHP Tutorial > Introduction to PHP Simple Adapter Pattern

Introduction to PHP Simple Adapter Pattern

巴扎黑
Release: 2023-03-15 09:16:02
Original
1367 people have browsed it

This article mainly introduces the simple adapter mode implemented by PHP, and analyzes the implementation skills and calling methods of the PHP adapter mode based on specific examples. Friends in need can refer to it

The examples in this article describe the implementation of PHP Simple adapter pattern. Share it with everyone for your reference, the details are as follows:


<?php
//适配器模式-通过适配器去执行第三方方法
//定义目标接口
interface Target{
  public function simpleMethod1();
  public function simpleMethod2();
}
class Adatee{
  public function simpleMethod1(){
    echo &#39;Adatee simpleMethod1<br/>&#39;;
  }
}
//类适配器模式
class Adapter implements Target{
  private $adatee;
  public function __construct(Adatee $adatee){
    $this->adatee = $adatee;
  }
  public function simpleMethod1(){
    echo $this->adatee->simpleMethod1();
  }
  public function simpleMethod2(){
    echo $this->adatee->simpleMethod12();
  }
}
//客户端接口
class Client{
  public static function main(){
    $adapter = new Adapter(new Adatee());
    $adapter->simpleMethod1();
  }
}
Client::main();
Copy after login

The above is the detailed content of Introduction to PHP Simple Adapter Pattern. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template