php教程|php手册
php组合 – w&y
php教程-php手册
为了提高代码的复用性,降低代码的耦合(组合实现的两种方式)
directx高级动画制作 源码,vscode是什么颜色的,ubuntu硬盘标记,tomcat端口加目录,完美世界爬虫,php连接mysql错误,晋安区提供seo报价,免费下载C 源码网站,企业oa平台网站模板下载不了lzw
模式一:
防伪验证源码,ubuntu环境下载jdk,tomcat给应用分配端口,爬虫技术意思,php获取影片时长,seo 优惠lzw
1 <?php 2 //组合模式一 3 class Person{ 4public function eat(){ 5 echo "eat.
"; 6} 7 } 8 9 class Phone{10public function call(){11 echo "phone call.
";12}13 }14 15 //学生也需要call()这个方法,为了提高代码的复用性(组合)16 class Student extends Person{17private $people;18public function learning(){19 echo "learn.
";20}21public function func($class, $method){//兼容多个类的多个方法22 $this->people = new $class;23 $this->people->$method();24}25 }26 27 $student = new Student();28 $student->eat();29 $student->func(Phone, call);30 $student->learning();
模式二:
html 登陆页面源码下载,n8000 ubuntu,tomcat宕机后台无报错,谷歌爬虫 封,php培训反思,图木舒克关键词seo优化lzw
1 <?php 2 //组合模式二 3 class Person{ 4public function eat(){ 5 echo "eat.
"; 6} 7 } 8 9 trait Drive{10public function call(){11 echo "phone call.
";12}13 }14 15 class Student extends Person{16use Drive;17public function learning(){18 echo "learn.
";19}20 }21 22 $student = new Student();23 $student->eat();24 25 //当方法或属性同名时,当前类中的方法会覆盖 trait的 方法,而 trait 的方法又覆盖了基类中的方法26 $student->call();27 $student->learning();
View Code