接口的使用能让开发更少的遗漏功能代码

1创建一个接口文件

game_interface.php

<?php
namespace Home\Tool;;
use Home\Tool;
/**
* Created by PhpStorm.
* User: smile
* Date: 2018/1/4
* Time: 20:36
*/
interface game_interface
{
public static function caiji();
public static function js();
public static function save();
public static function check_guize();
public static function fanshui();
}

2,创建一个类来继承这个接口

Game.class.php

<?php

namespace Home\Tool;;
use Home\Tool;

/**
* Created by PhpStorm.
* User: smile
* Date: 2018/1/4
* Time: 20:36
*/
abstract class Game implements game_interface{

}

3 功能类再去继承 Game

Pk10.class.php

<?php

namespace Home\Tool;
use Home\Tool;

class Pk10 extends Game {
public static $name ="北京赛车";
public static function js()
{
// TODO: Implement js() method.
caiji();
}

public static function caiji()
{
// TODO: Implement caiji() method.
}

public static function save()
{
// TODO: Implement save() method.
}

public static function check_guize()
{
// TODO: Implement check_guize() method.
}


public static function fanshui()
{
// TODO: Implement fanshui() method.
}
}

extends 扩展类的时候用的时phpstrom工具,会自动生成代码,如上面所示。如果上面的代码少了方法,就会提示错误,鼠标移至game 上, 按住 alt + enter 键,自动添加