Last active
August 19, 2017 13:59
-
-
Save yuyu-TZ321/a36e5740bf6af090bea8ded1de5d455d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface Info | |
{ | |
public function channelMessage(); | |
} | |
abstract class Live | |
{ | |
const RANGE = 10; | |
protected $point = 0; | |
abstract protected function loginchat(); | |
public function onLive() | |
{ | |
$this->point += self::RANGE * 10; | |
echo $this->point . "\r\n"; | |
} | |
public final function offLive() | |
{ | |
$this->point += self::RANGE * 1; | |
echo $this->point . "\r\n"; | |
} | |
} | |
class Twitch extends Live implements Info | |
{ | |
private $channelname; | |
public function __construct($name) | |
{ | |
$this->channelname = $name; | |
echo "Welcome to " . $this->channelname . " channel\r\n"; | |
} | |
protected function loginChat() | |
{ | |
echo "Log in " . $this->channelname . " chat\r\n"; | |
} | |
public function channelMessage() | |
{ | |
$this->loginChat(); | |
echo "This is " . $this->channelname . " \r\n"; | |
} | |
public static function liveType() | |
{ | |
echo "TWITCH \r\n"; | |
} | |
} | |
class FbLive extends Live implements Info | |
{ | |
//計算觀看人數 | |
private $num = 0; | |
public function __construct() | |
{ | |
$this->num++; | |
} | |
protected function loginChat() | |
{ | |
echo "welcome fb live chat\r\n"; | |
} | |
public function channelMessage() | |
{ | |
$this->loginChat(); | |
echo "This num " . $this->num . " \r\n"; | |
} | |
public static function liveType() | |
{ | |
echo "FaceBook \r\n"; | |
} | |
} | |
$fbLive = new FbLive(); | |
$fbLive->onLive(); | |
$fbLive->channelMessage(); | |
$fbLive->offLive(); | |
fbLive::liveType(); | |
$twitch = new Twitch('yuyu0321'); | |
$twitch->onLive(); | |
$twitch->channelMessage(); | |
$twitch->offLive(); | |
Twitch::liveType(); |
- 所有的 method 都要有 public, protected, private,包含 construct
- 換行也可以使用
PHP_EOL
- method 間隔一行, properties 間不用
- properties 和 methods 間隔一行
- . 前後要空隔
echo $this->point."\r\n"; echo $this->point . "\r\n";
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
class live
?>