a framework for Divine

满有意思的框架 

<?php

ini_set ( ‘display_errors’, ‘true’ ); interface God {
        public function bless (Human $who );
        public function heal (Human $who );
        public function save (Human $who );
}

class Human {
        public $name;
        public $health = 0;         public $abundance = 0;
        public $saved = false;

        public function __construct ( $name ) {
                $this-> name = $name;
        }

        public function __toString () {
                $out = “Hello there. I am $this->name. “;

                if ( $this-> health > 0 ) {
                        $out .= “I am healthy. “;
                }
                else {
                        $out .= “I am sick. “;
                }

                if ( $this-> abundance > 0 ) {
                        $out .= “I am abundant. “;
                }
                else {
                        $out .= “I am poor. “;
                }

                if ( $this-> saved ) {
                        $out .= “I am going to Heaven!!”;
                }
                else {
                        $out .= “I am screwed.”;
                }

                return $out;
        }

        public function __destruct () {
                echo $this->__toString ();
        }
}

class JesusChrist extends Human implements God {
        public $health = 100;
        public $abundance = 100;
        public $saved = true; // duh
        public static $savedCount = 0;

        public function bless (Human $who ) {
                $who-> abundance++;
        }

        public function heal (Human $who ) {
                $who-> health++;
        }

        public function save (Human $who ) {
                $who-> saved = true;
                self:: $savedCount++;
        }

        public function __toString () {
                $out = parent::__toString ();
                return $out . ‘And I have brought ‘.self:: $savedCount. ‘ people back to God.’;
        }
}

$JC = new JesusChrist ( ‘Jesus Christ’ );

$me = new Human ( ‘Mike G.’ );
$you = new Human ( ‘Daniel W.’ );
$other = new Human ( ‘John D.’ );

$JC-> save ( $me );
$JC-> bless ( $me );
$JC-> heal ( $me );

$JC-> save ( $you );
$JC-> bless ( $you );
$JC-> heal ( $you );

// Then we die and our destructors are called…

?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值