PHP abstract ºÍ interfaceµÄÇø±ð
1.php ½Ó¿ÚÀà:interface
ÆäʵËûÃǵÄ×÷Óúܼòµ¥£¬µ±ÓкܶàÈËÒ»Æ𿪷¢Ò»¸öÏîĿʱ£¬¿ÉÄܶ¼»áÈ¥µ÷ÓñðÈËдµÄһЩÀ࣬ÄÇÄã¾Í»áÎÊ£¬ÎÒÔõô֪µÀËûµÄij¸ö¹¦ÄܵÄʵÏÖ·½·¨ÊÇÔõôÃüÃûµÄÄØ£¬Õâ¸öʱºòphp½Ó¿ÚÀà¾ÍÆðµ½×÷ÓÃÁË£¬µ±ÎÒÃǶ¨ÒåÁËÒ»¸ö½Ó¿ÚÀàʱ£¬ËüÀïÃæµÄ·½Ê½ÊÇÏÂÃæµÄ×ÓÀà±ØÐëʵÏֵģ¬±ÈÈç :
interface Shop { public function buy($gid); public function sell($gid); public function view($gid); } ÎÒÉùÃ÷Ò»¸öshop½Ó¿ÚÀ࣬¶¨ÒåÁËÈý¸ö·½·¨£ºÂò(buy),Âô(sell),¿´(view),ÄÇô¼Ì³Ð´ËÀàµÄËùÓÐ×ÓÀ඼±ØÐëʵÏÖÕâ3¸ö·½·¨ÉÙÒ»¸ö¶¼ ²»ÐУ¬Èç¹û×ÓÀàûÓÐʵÏÖÕâЩ»°£¬¾ÍÎÞ·¨ÔËÐС£Êµ¼ÊÉϽӿÚÀà˵°×ÁË£¬¾ÍÊÇÒ»¸öÀàµÄÄ£°å£¬Ò»¸öÀàµÄ¹æ¶¨£¬Èç¹ûÄãÊôÓÚÕâÀ࣬Äã¾Í±ØÐë×ñÑÎҵĹ涨£¬ÉÙÒ»¸ö¶¼²» ÐУ¬µ«ÊǾßÌåÄãÔõôȥ×ö£¬ÎÒ²»¹Ü£¬ÄÇÊÇÄãµÄÊ£¬È磺class BaseShop implements Shop { public function buy($gid) { echo('Ä㹺ÂòÁËIDΪ :'.$gid.'µÄÉÌÆ·'); } public function sell($gid) { echo('ÄãÂôÁËIDΪ :'.$gid.'µÄÉÌÆ·'); } public function view($gid) { echo('Äã²é¿´ÁËIDΪ :'.$gid.'µÄÉÌÆ·'); } } ÄãÏëÏ룬ÔÚÒ»¸ö¶àÈ˺Ï×÷µÄ´óÏîÄ¿ÀïÃ棬ÓÐÁ˽ӿÚÀàÊǶàôµÄ·½±ã£¬ÕâÑùÄã¾Í²»ÓÃÈ¥ÎʱðÈË£¬ÄãµÄijij¹¦Äܵķ½·¨ÃûÊÇʲôÁË£¬µ±È»Èç¹ûÄãÃÇϲ»¶ÕâÑùÎÒҲûÓа취¡£
½áÂÛ £º ½Ó¿ÚÀà¾ÍÊÇÒ»¸öÀàµÄÁìµ¼Õߣ¬Ö¸Ã÷·½Ïò£¬×ÓÀà±ØÐëÍê³ÉËüÖ¸¶¨·½·¨¡£
2.php ³éÏóÀà : abstract
Æäʵ³éÏóÀàºÍ½Ó¿ÚÀàÓÐÒ»²¿·ÖºÜÏñ£¬¼ÇµÃÔÚÄÄÀï¿´¼ûÕâÑùÒ»¾ä»°£¬³éÏóÀà¾Í°ÑÀàÏñµÄ²¿·Ö³é³öÀ´£¬Õâ¾ä¿´ÉÏÈ¥ºÜ¸ãЦ£¬ÆäʵËü˵³öÁ˳éÏóÀàµÄÕæÀí£¬³éÏóÀàµÄ×÷ÓÃÊÇ£¬µ±Äã·¢ÏÖÄãµÄºÜ¶àÀàÀïÃæÓúܶ෽·¨Äã²»¶ÏµÄÔÚÖظ´Ð´£¬ÄÇÄã¾Í¿ÉÒÔ¿¼ÂÇʹÓóéÏóÀàÁË£¬Äã¿ÉÄÜ»á˵¡°ÎÒ²»ÊÇ¿ÉÒÔÖØдһ¸öÀàÿ¸ö¹«¹²ÀàÎÒ¸öʵÀý»¯Ò»¸öÕâ¸ö¹«¹²À࣬µ÷ÓÃÏàͬµÄ·½·¨¾Í¿ÉÒÔÁË¡±£¬ÕâÀïÊÇ¿ÉÒÔ£¬Êµ¼ÊÉϳéÏóÀà×öµÄ¹¤×÷Ò²¾ÍÊÇÕâ¸ö£¬²»¹ýËûÊ¡È¥ÁËÄãʵÀý»¯µÄÕâ¸ö²½Ö裬ÈÃÄã¾ÍÏñÖ±½Óµ÷Óñ¾Àà·½·¨Ò»Ñù·½±ã£¬¶øÇÒÄ㻹¿ÉÒÔÖØÔØÕâ¸ö·½·¨¡£È磺
abstract class BaseShop { public function buy($gid) { echo('Ä㹺ÂòÁËIDΪ :'.$gid.'µÄÉÌÆ·'); } public function sell($gid) { echo('ÄãÂôÁËIDΪ :'.$gid.'µÄÉÌÆ·'); } public function view($gid) { echo('Äã²é¿´ÁËIDΪ :'.$gid.'µÄÉÌÆ·'); } } class BallShop extends BaseShop { var $itme_id = null; public function __construct() { $this->itme_id = 2314; } public function open() { $this->sell($this->itme_id); } }
ÕâÀïÊÇÒ»¸öÀý×Ó£¬ÏëÉÏÃæÒ»ÑùÎÒ¶¨ÒåÁËÒ»¸öÉ̵êÀ࣬³é³öÁËËüËùÓÐÏñµÄ²¿·Ö£¬Âò(buy),Âô(sell),¿´(view),²¢ÇÒ³éÏóÀàÀﶼʵÏÖÁËÕâЩ·½·¨£¬ÄÇô¼Ì³ÐËüµÄ×ÓÀà¾Í×Ô¶¯»ñµÃÁËÕâЩ·½·¨£¬×ÓÀà¾Í×öËü×Ô¼º¶ÀÌصĶ«Î÷£¬½éÉÜ´úÂëµÄÖظ´£¬Ìá¸ß¸´ÓÃÐÔ¡£
½á ÂÛ£º ³éÏóÀà¾ÍÊÇÒ»¸öÀàµÄ·þÎñÌṩÉÌ£¬ÓµÓÐÖÚ¶à·þÎñ£¬Äã²»ÓñØÐëÓ㬵±ÐèÒªµÄʱºòÄãÀ´ÓþͿÉÒÔ£¬Èç¹ûÄã¾õµÃËùÌṩ·þÎñ²»ÂúÒ⣬Ä㻹¿ÉÒÔ×Ô¼ºÀ´×ö¡£¶ø abstract function ·½·¨ºÍinterfaceÓÐЩÏàËÆ£¬¾ÍÊǸ¸ÀàÖÐÉúÉùÃ÷µÄ·½·¨£¬×ÓÀàÖбØÐëʵÏÖ£¬µ«ÊÇûÓÐÓÃabstractÉùÃ÷µÄ·½·¨½«³ÉΪ×ÓÀàµÄ¹«¹²·½·¨£¬Ã»ÓбØÒªÔÚ×ÓÀàÖбØÐëʵÏÖ¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ