Blogger Information
Blog 28
fans 0
comment 0
visits 15754
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0813 作业
︷肉園耔︷
Original
669 people have browsed it
  1. <?php
  2. /*
  3. *接口 interface 接口是定义 类是实现 trait结构 解决oop 高耦合
  4. *
  5. *
  6. *
  7. */
  8. interface Idemo{
  9. //接口中只允许声明两类成员 1.接口常量 2.公共的抽象方法
  10. const APP_NAME='heidemi小铺';
  11. public static function getInfo(...$info);
  12. public static function cal($one,$two);
  13. }
  14. interface Idemo2{
  15. }
  16. //接口的实现 implements
  17. class Work implements Idemo{
  18. static function getInfo(...$info){
  19. return print_r($info,true);
  20. }
  21. static function cal($one,$two){
  22. return $one * $two;
  23. }
  24. }
  25. ECHO work::APP_NAME;
  26. ECHO Idemo::APP_NAME;
  27. ob_clean();
  28. echo Work::getInfo('古力娜扎','28',172,'新疆');
  29. echo Work::cal(58,69);
  30. /*
  31. *工作类 extends 抽象类(普通类) imple
  32. */
  33. echo '<hr>';
  34. /* oop 封装 继承 多台
  35. 多态实现了动态绑定的功能
  36. */
  37. //为计算机(主程序)扩展功能 接口是定义
  38. interface USB{
  39. function run();
  40. }
  41. //为计算机扩展功能 扩展了一个USB键盘 实现USB接口
  42. class Ukey implements USB {
  43. function run(){
  44. return '运行USB键盘设备<br>';
  45. }
  46. }
  47. class Umemo implements USB{
  48. function run(){
  49. return '运行USB 储存盘设备<br>';
  50. }
  51. }
  52. class Umouse implements USB{
  53. function run(){
  54. return '运行USB鼠标设备<br>';
  55. }
  56. }
  57. //主程序计算机
  58. class Computer{
  59. //计算机类中的一个方法 就可以应用任意一种方法USB设备
  60. function useUSB($usb) //参数是一个对象
  61. {
  62. return $usb->run();
  63. }
  64. }
  65. $c =new Computer;
  66. echo $c->useUSB(new Umouse());
  67. echo $c->useUSB(new Ukey());
  68. <?php
  69. //单例模式连接数据库
  70. //
  71. interface iDbBase{
  72. //数据库操作curd
  73. static function insert($db,$data);
  74. static function slelect($db,$where=[]);
  75. static function daleta($db,$where=[]);
  76. static function updata($db,$data,$where=[]);
  77. static function doConnect($dns,$username,$password);
  78. }
  79. abstract class aDb implements iDbBase{
  80. //创建类的唯一实例 PDO对象s
  81. private static $_instance;
  82. //private 私有的 阻止此类在外部进行实例化
  83. private function __Construct(){
  84. }
  85. private function __clone(){
  86. }
  87. static function doConnect($dns,$username,$password){
  88. //得到pdo连接对象,储存在$_instance
  89. if($is_null(self::$_instance)){
  90. self::$_instance =new PDO($dns,$username,$password);
  91. }
  92. return self::$_instance;
  93. }
  94. }
  95. //工作类
  96. class DB extends aDb{
  97. static function insert($db,$data){
  98. };
  99. static function slelect($db,$where=['gender'=>1]){
  100. //select filed .. form tablename where gender=1 and id>1
  101. $str='';
  102. foreach($where as $k=>$v){
  103. if(is_array($where)){
  104. if(count($where) >1){
  105. $str .=$k .'='.$v.'and';
  106. }else{
  107. $str .=$k .'='.$v;
  108. }
  109. }
  110. }
  111. return $db->query("SELECT 'name" , 'tel' FROM 'iuser' WHERE $str")->fetchall(PDO::FETCH_ASSOC)
  112. };
  113. static function daleta($db,$where=[]){
  114. };
  115. static function updata($db,$data,$where=[]){
  116. };
  117. static function doConnect($dns,$username,$password){
  118. }
  119. }
  120. //客服端 代码
  121. $dsn = 'mysql:host=39.105.79.62;dbname=news';
  122. $db=Db:doConnect($dsn,'root','zhoujielun521'){
  123. var_dump($db);
  124. Db::select($db);
  125. print_r(Db::select($db));
  126. //
  127. ?>
Correcting teacher:PHPzPHPz

Correction status:unqualified

Teacher's comments:作业标题改为内容
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post