标签:des style blog color io sp div c on
<?php interface Computer { public function version(); public function work(); } class NoteComputer implements Computer { public function version(){ echo ‘笔记本‘; } public function work(){ echo ‘可以便携运行WIN7!!‘; } } class DesktopComputer implements Computer { public function version(){ echo ‘台式机!‘; } public function work(){ echo ‘在工作站运行XP!‘; } } class Person { public function _run($type){ echo ‘这个人的‘; $type->version(); $type->work(); } } //多态的原理就是,类都写好了~不要去修改它~只要在类外的调用参数更改 //最后的结果也会修改,那么这个就是多态 $notecomputer = new NoteComputer(); $desktopcomputer = new DesktopComputer(); $person = new Person(); $person->_run($notecomputer); //对象引用传递,持有对方的引用 echo ‘<br/>‘; $person->_run($desktopcomputer); ?>
标签:des style blog color io sp div c on
原文地址:http://www.cnblogs.com/oceanden/p/4006159.html