`
dcdc723
  • 浏览: 183521 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

PHP 多态简单示例

    博客分类:
  • PHP
PHP 
阅读更多
<?php
 interface myusbkou
 {
   function type();//类型
   function action();//执行的操作
 }
 class zip implements myusbkou
 {  //继承接口
    function type(){
	  echo "USB的2.0接口";
   }
    function action(){
	  echo "--->需要USB 2.0驱动";
   }
}
 class mp3 implements myusbkou{
 	function type()
 	{
     echo "MP3的1.0接口";
 	}
 	function action()
 	{
     echo "--->需要MP3 1.0驱动<br/>";
 	}
}
class mypc{
	function usbthing($thing)
	{
     $thing->type();
     $thing->action();
	}
}
$p=new mypc();
$mp3=new mp3();
$zip=new zip();
$p->usbthing($mp3);
$p->usbthing($zip);
?>

 

1
0
分享到:
评论
1 楼 xiaolin0105 2010-03-25  
吓死了,php也开始搞这套了

相关推荐

Global site tag (gtag.js) - Google Analytics