We are learning throughvideocard.php interface file (function interface definition for graphics card)
- Php
- Interface videocardinter{
- function Display ();
- function GetName ();
- }
- ?>
Dmeng.php implementation interface (deem manufacturers realize these interfaces, how to achieve, motherboard manufacturers do not tube)
- Php
- Include_once ("videocard.php");
- Class Dmeng implements Videocardinter {
- function Display () {
- echo "Display";
- }
- function GetName () {
- Return "Dmeng Videocard";
- }
- }
- ?>
mainboard.php Application Interface (plug the graphics card into the motherboard, the motherboard as long as the use of these interfaces on the line, also can not be used)
- php
- Include_once ("videocard.php");
- Include_once ("dmeng.php");
- Class mainboard{
- var $vc;
- function run (Videocardinter $VC) {//Defines the Videocardinter interface type parameter, and does not know who will implement it.
- $this- > VC = $VC;
- $this- > vc- > Display ();
- echo "Motherboard running! ";
- }
- }
- $ Conputer = New mainboard ();
- $conputer- > Run (new Dmeng); To write the name of the implementation interface class in the
(now it is deem's video card, can also be replaced by other field home, as long as they have implemented the interface)
- ?>
Because PHP is a dynamic language, so the type can not be the same as Java is dead, when defining the interface, write the return type error, it is estimated that the PHP6 may be written to be more strict.
PS: I only write the most basic parts of PHP interface features, you can also add CPU and other interfaces.
http://www.bkjia.com/PHPjc/446410.html www.bkjia.com true http://www.bkjia.com/PHPjc/446410.html techarticle We are learning videocard.php interface file (the function interface definition of graphics card)? PHP interfacevideocardinter{Functiondisplay (); Functiongetname ();}? dmeng.php implementation interface (Emperor ...