Home Backend Development PHP Tutorial Example explanation of PHP interface features_PHP tutorial

Example explanation of PHP interface features_PHP tutorial

Jul 15, 2016 pm 01:28 PM
p php Function exist definition Example us interface document graphics card of explain

We are learning the VideoCard.php interface file (functional interface definition of the graphics card)

<ol class="dp-xml"><li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>interface VideoCardInter{  </SPAN><LI class=alt><SPAN>    function Display();  </SPAN><LI class=""><SPAN>    function getName();  </SPAN><LI class=alt><SPAN>}  </SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span>
</li></ol>
Copy after login

Dmeng.php implements the interface (the manufacturers of Diamond have implemented these interfaces. How to implement them is not a matter of the motherboard manufacturer)

<ol class="dp-xml"><li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>include_once("VideoCard.php");  </SPAN><LI class=alt><SPAN>class Dmeng implements VideoCardInter {  </SPAN><LI class=""><SPAN>    function Display(){  </SPAN><LI class=alt><SPAN>        echo "Display";  </SPAN><LI class=""><SPAN>    }  </SPAN><LI class=alt><SPAN>    function getName(){  </SPAN><LI class=""><SPAN>        return "Dmeng VideoCard";  </SPAN><LI class=alt><SPAN>    }  </SPAN><LI class=""><SPAN>}  </SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span>
</li></ol>
Copy after login

Mainboard.php application interface (insert the graphics card into the motherboard, the motherboard only needs to use these interfaces, or not)

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>include_once("VideoCard.php");  </SPAN><LI class=alt><SPAN>include_once("Dmeng.php");  </SPAN><LI class=""><SPAN>class Mainboard{  </SPAN><LI class=alt><SPAN>    var $vc;  </SPAN><LI class=""><SPAN>    function run(VideoCardInter $vc){  //定义VideoCardInter接口类型参数,这时并不知道是谁来实现。  </SPAN><LI class=alt><SPAN>        $this-</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong></span><span class="attribute"><font color="#ff0000">vc</font></span><span>=$vc;  </span>
</li>
<li class="">
<span>        $this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>vc-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>Display();  </span>
</li>
<li class="alt"><span>        echo "主板运行!";  </span></li>
<li class=""><span>    }  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">conputer</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">new</font></span><span> Mainboard();  </span>
</li>
<li class="alt">
<span>$conputer-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>run(new Dmeng);  //用的时候把实现接口类的名称写进来,<br>(现在是帝盟的显卡,也可以换成别的场家的,只要他们都实现了接口)  </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>
Copy after login

Since PHP is a dynamic language, the type cannot be like JAVA The definition is very rigid. When defining the interface, it will make an error to write the return type. I guess in PHP6, the definition may be more strict.

PS: I only wrote the most basic part of the PHP interface features, and you can also add CPU and other interfaces.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446410.htmlTechArticleWe are studying the VideoCard.php interface file (functional interface definition of the graphics card) ? php interfaceVideoCardInter{ functionDisplay(); functiongetName(); } ? Dmeng.php implements the interface (Emperor...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles