接口 2018-11-24 14:04

代码:

<?php
header('Content-type:text/html;charset=utf-8');

interface Animal{
	public function show();
}

// 猫的类型
class Cat implements Animal{
	protected $name;
	public $age;
	public $color;

	public $tiao_height;
	public function __construct($name,$age,$color,$tiao_height){
		$this->name=$name;
		$this->age=$age;
		$this->color=$color;
		$this->tiao_height=$tiao_height;
		echo 'Cat<br />';
	}

	public function show(){
		echo "名字:{$this->name}<br />";
		echo "年龄:{$this->age}岁<br />";
		echo "颜色:{$this->color}<br />";
		echo "跳的高度:{$this->tiao_height}米<br />";
	}

}


// 鸟的类型
class Bird implements Animal{
	protected $name;
	public $age;
	public $color;
	public $fei_sudu;

	public function __construct($name,$age,$color,$fei_sudu){
		$this->name=$name;
		$this->age=$age;
		$this->color=$color;
		$this->fei_sudu=$fei_sudu;
		echo 'Bird<br />';
	}

	public function show(){
		echo "名字:{$this->name}<br />";
		echo "年龄:{$this->age}岁<br />";
		echo "颜色:{$this->color}<br />";
		echo "飞的速度:{$this->fei_sudu}米/秒<br />";
	}

}

// 青蛙的类型
class QingWa implements Animal{
	protected $name;
	public $age;
	public $color;
	public $youyong_shengdu;

	public function __construct($name,$age,$color,$youyong_shengdu){
		$this->name=$name;
		$this->age=$age;
		$this->color=$color;
		$this->youyong_shengdu=$youyong_shengdu;
		echo 'QingWa<br />';
	}

	public function show(){
		echo "名字:{$this->name}<br />";
		echo "年龄:{$this->age}岁<br />";
		echo "颜色:{$this->color}<br />";
		echo "我游泳的深度:{$this->youyong_shengdu}分米<br />";
	}

}

// ------------------------------------------
// 我的工具类
class Tool{
	public static function get_infos($a){
		$a->show();
	}
}

// $a=new Animal('一只动物',1,'蓝色');
// $a->show();
// echo $a->name;

$c=new Cat('一只猫',2,'灰色',3);
// $c->show();

$b=new Bird('猫头鹰',3,'白色',20);
// $b->show();

Tool::get_infos($c);
Tool::get_infos($b);

$qw=new QingWa('一只青蛙',5,'青色',6);
Tool::get_infos($qw);



USB


电脑上开一个接口,你插上U盘,移动硬盘,MP4,手机,通信。

Tool::get_infos();