PHPÖÐÓýӿڡ¢³éÏóÀà¡¢ÆÕͨ»ùÀàʵÏÖ¡°ÃæÏò½Ó¿Ú±à³Ì¡±Óë¡°ñîºÏ·½·¨¡±¼òÊö
<?php /* ±ßѧ±ß×öµÄ£¬Îª·½±ã×Ô¼º·ÔĶø·¢²¼£¬¸üΪµÃµ½¸ßÈËÖ¸µã¶ø·¢²¼£¬»¶Ó¸ßÊÖÖ¸µã...... ¡¾Ìáʾ¡¿±¾Àýͨ¹ý²âÊÔÎÞÎó ¡¾Çé¾°Éè¼Æ¡¿ Ä£Äâ¼ÆËã»úÖ÷°åIDE½Ó¿Ú£¬±ÈÈ磺Ö÷°å¿ÉÒÔ´æÈ¡µÄ´¢´æÆ÷³£³£ÓйâÇý¡¢Ó²ÅÌ¡¢ÉÁ´æµÈµÈ£¬ ΪÁË·½±ã£¬ÓбØÒª¶ÔÕâЩ²»Í¬µÄ´¢´æÆ÷É趨ͬһµÄ½Ó¿Ú¡£ ±¾Àý»¹¼ÙÉèÒ»ÖÖÇ°ËùδÓеġ¢´æÈ¡·½Ê½ÓëÖÚ²»Í¬µÄÍâÐÇ´¢´æÆ÷Ò²Òª¼Óµ½Ö÷°åÉϽøÐдæÈ¡£¬ ÓÚÊÇÐèÒª²ÉÓÃñîºÏµÄÉè¼Æģʽ¡£ ¡¾±¾ÀýÖ÷Òª½²Êö¡¿ 1¡¢Í¨¹ý½Ó¿Ú¡¢³éÏóÀà¡¢Ò»°ãÀà¼Ì³ÐÈýÖÖ·½Ê½´ïµ½ËùνµÄ¡°½Ó¿Ú¡±Ä£Ê½£¬ÒÔ´Ë˵Ã÷£º A¡¢×ÓÀà¶ÔÏó¿ÉÒÔµ±¸¸Àà¶ÔÏóÓã¬ÒòΪ×ÓÀàÊÇÌØÊâµÄ¸¸À࣡ B¡¢Çë×¢ÒâÕâÈýÖÖʵÏÖ·½Ê½Öнӿڡ¢³éÏóÀàºÍÒ»°ãÀà¼Ì³ÐµÄ»ùÀàд·¨£¡ 2¡¢½Ó¿ÚģʽÕæµÄÊÇÒ»Ö½ÆõÔ¼£¡ 3¡¢³ÌÐòÉè¼ÆÖ®"ñîºÏÉè¼Æģʽ"£¡ */ //---------------------------------------------------------------------- /*¡¾·½Ê½Ò»¡¿½Ó¿ÚʵÏÖ·½Ê½:*/ interface readandwrite{ function read(); function write(); } class motherboard{ private $storage; function __construct(readandwrite $obj){ $this->storage=$obj; } function read(){ $this->storage->read(); } function write(){ $this->storage->write(); } } class flash implements readandwrite{ function __construct(){ echo "ÎÒÊÇÉÁ´æ£º<br>"; } function read(){ echo "¿ªÊ¼¶ÁÈ¡Êý¾Ý......<br>"; } function write(){ echo "¿ªÊ¼´¢´æÊý¾Ý......<hr>"; } } class yingpan implements readandwrite{ function __construct(){ echo "ÎÒÊÇÓ²ÅÌ£º<br>"; } function read(){ echo "¿ªÊ¼¶ÁÈ¡Êý¾Ý......<br>"; } function write(){ echo "¿ªÊ¼´¢´æÊý¾Ý......<hr>"; } } class disco implements readandwrite{ function __construct(){ echo "ÎÒÊǹâÅÌ£º<br>"; } function read(){ echo "¿ªÊ¼¶ÁÈ¡Êý¾Ý......<br>"; } function write(){ echo "¿ªÊ¼´¢´æÊý¾Ý......<hr>"; } } //---------------------------------------------------------------------- /*¡¾·½Ê½¶þ¡¿³éÏóÀàʵÏÖ·½Ê½: abstract class readandwrite{ abstract function read(); abstract function write(); } class motherboard{ private $storage; function __construct(readandwrite $obj){ $this->storage=$obj; } function read(){ $this->storage->read(); } function write(){ $this->storage->write(); } } class flash extends readandwrite{ function __construct(){ echo "ÎÒÊÇÉÁ´æ£º<br>"; } function read(){ echo "¿ªÊ¼¶ÁÈ¡Êý¾Ý......<br>"; } function write(){ echo "¿ªÊ¼´¢´æÊý¾Ý......<hr>"; } } class yingpan extends readandwrite{ function __construct(){ echo "ÎÒÊÇÓ²ÅÌ£º<br>"; } function read(){ echo "¿ªÊ¼¶ÁÈ¡Êý¾Ý......<br>"; } function write(){ echo "¿ªÊ¼´¢´æÊý¾Ý......<hr>"; } } class disco extends readandwrite{ function __construct(){ echo "ÎÒÊǹâÅÌ£º<br>"; } function read(){ echo "¿ªÊ¼¶ÁÈ¡Êý¾Ý......<br>"; } function write(){ echo "¿ªÊ¼´¢´æÊý¾Ý......<hr>"; } } */ //---------------------------------------------------------------------- //¡¾·½Ê½Èý¡¿Ò»°ãÀà¼Ì³ÐʵÏÖ·½Ê½£º /* class readandwrite{ function read(){ echo "reading.............."; } function write(){ echo "writing.............."; } } class motherboard{ private $storage; function __construct(readandwrite $obj){ $this->storage=$obj; } function read(){ $this->storage->read(); } function write(){ $this->storage->write(); } } class flash extends readandwrite{ function __construct(){ echo "ÎÒÊÇÉÁ´æ£º<br>"; } function read(){ echo "¿ªÊ¼¶ÁÈ¡Êý¾Ý......<br>"; } function write(){ echo "¿ªÊ¼´¢´æÊý¾Ý......<hr>"; } } class yingpan extends readandwrite{ function __construct(){ echo "ÎÒÊÇÓ²ÅÌ£º<br>"; } function read(){ echo "¿ªÊ¼¶ÁÈ¡Êý¾Ý......<br>"; } function write(){ echo "¿ªÊ¼´¢´æÊý¾Ý......<hr>"; } } class disco extends readandwrite{ function __construct(){ echo "ÎÒÊǹâÅÌ£º<br>"; } function read(){ echo "¿ªÊ¼¶ÁÈ¡Êý¾Ý......<br>"; } function write(){ echo "¿ªÊ¼´¢´æÊý¾Ý......<hr>"; } } */ //---------------------------------------------------------------------- /* ¡¾ñîºÏģʽ¡¿ ñîºÏģʽ¾ÍÊǽ«²»Í¬±ê×¼µÄÁ½¸öÀࣨ±¾ÀýµÄ½Ó¿Ú¡¢³éÏóÀà¡¢ÆÕͨ»ùÀàÓëÍâÐÇ´¢´æÆ÷Óв»Í¬µÄ´æÈ¡·½·¨£©£¬ ͨ¹ýÖмäת»»Æ÷£¬´ïµ½Í¬Ò»±ê×¼µÄÄ¿µÄ£¬¾ÍÏñת½ÓÏßÒ»Ñù¡ª¡ª±¾Àý¾ÍÊǽ«unknowÀàµÄRdata¡¢Wdata·½·¨×ª »»³Éread¡¢write·½·¨£¬´ïµ½ºÍ±¾ÀýµÄ½Ó¿Ú¡¢³éÏóÀà¡¢ÆÕͨ»ùÀàÏàͬµÄ´æÈ¡·½·¨£¬ ±¾ÀýµÄÖмäת»»Æ÷ÊÇ ApdaterÀà¡£ ÓÉÓÚphpÖÐÖ»Äܼ̳ÐÒ»¸öÀ൫¿ÉÒԼ̳жà¸ö½Ó¿Ú£¬ËùÒÔ²úÉúÁËÈýÖÖñîºÏ·½·¨£º ·½·¨Ò»£ºÖмäת»»Æ÷ApdaterÀà¼Ì³Ð³éÏóÀà»òÆÕͨ»ùÀ࣬µ«ÓÉÓÚphpÖÐÖ»Äܼ̳ÐÒ»¸öÀ࣬ËùÒÔÔÚApdater ÀàÖж¨ÒåÒ»¸öÍâÐÇ´æ´¢Æ÷ÀàunknowµÄ¶ÔÏ󣬲¢ÓÃÖØÔؼ̳еijéÏóÀà»òÆÕͨ»ùÀàµÄ´æÈ¡·½·¨µÄ·½Ê½À´×ª »»´æÈ¡·½·¨£¬´ïµ½Í¬Ò»´æÈ¡·½·¨µÄÄ¿µÄ¡£ ·½·¨¶þ£ºÖмäת»»Æ÷ApdaterÀà¼Ì³ÐÍâÐÇ´æ´¢Æ÷Ààunknow¡¢½Ó¿Ú£¬´Ëʱ¿ÉÒÔÖ±½ÓÓÃApdaterÀàµÄ´æÈ¡·½·¨ (parent::Rdata()Óëparent::Wdata()¡ª¡ªphpÖÐ×ÓÀàµ÷Óø¸Àà·½·¨µÄ·½Ê½)£¬ºÍʵÏֽӿڹ涨·½·¨£¬ À´×ª»»´æÈ¡·½·¨£¬´ïµ½Í¬Ò»´æÈ¡·½·¨µÄÄ¿µÄ¡£ ·½·¨Èý£ºÓë·½·¨Ò»À×ͬ£¬Ö»ÊǸÄΪ¼Ì³Ð£¨ÊµÏÖ£©½Ó¿Ú£» */ //---------------------------------------------------------------------- /* ¡¾·½·¨Ò»¡¿ */ /* class unknow{ function __construct(){ echo "<font color=#ff0000>ÎÒÊǵØÇòÈËδ֪µÄÍâÐÇ´¢´æÆ÷£¬ÎÒÓв»Í¬ÓÚµØÇò´¢´æÆ÷µÄ´æÈ¡·½Ê½£º</font><br>"; } function Rdata(){ echo "I'm reading now......<br>"; } function Wdata(){ echo "I'm writing now......<hr>"; } } class Adpater extends readandwrite{ private $obj; function __construct(unknow $x){ $this->obj=$x; } function read(){ $this->obj->Rdata(); } function write(){ $this->obj->Wdata(); } } */ //---------------------------------------------------------------------- /* ¡¾·½·¨¶þ¡¿ class unknow{ function __construct(){ echo "<font color=#ff0000>ÎÒÊǵØÇòÈËδ֪µÄÍâÐÇ´¢´æÆ÷£¬ÎÒÓв»Í¬ÓÚµØÇò´¢´æÆ÷µÄ´æÈ¡·½Ê½£º</font><br>"; } function Rdata(){ echo "I'm reading now......<br>"; } function Wdata(){ echo "I'm writing now......<hr>"; } } class Adpater extends unknow implements readandwrite{ function read(){ parent::Rdata(); } function write(){ parent::Wdata(); } } */ //------------------------------------------------------------------------ /* ¡¾·½·¨Èý¡¿ */ class unknow{ function __construct(){ echo "<font color=#ff0000>ÎÒÊǵØÇòÈËδ֪µÄÍâÐÇ´¢´æÆ÷£¬ÎÒÓв»Í¬ÓÚµØÇò´¢´æÆ÷µÄ´æÈ¡·½Ê½£º</font><br>"; } function Rdata(){ echo "I'm reading now......<br>"; } function Wdata(){ echo "I'm writing now......<hr>"; } } class Adpater implements readandwrite{ private $obj; function __construct(unknow $x){ $this->obj=$x; } function read(){ $this->obj->Rdata(); } function write(){ $this->obj->Wdata(); } } //¡¾³ÌÐòÖ÷Ìåµ÷Óá¿ echo "<strong><font color=#990000 size=20px>ÃæÏò¶ÔÏó³ÌÐòÉè¼Æ¡ª¡ª½Ó¿Ú</font></strong><hr>"; $storage1=new flash(); $computer=new motherboard($storage1); $computer->read(); $computer->write(); $storage2=new yingpan(); $computer=new motherboard($storage2); $computer->read(); $computer->write(); $storage3=new disco(); $computer=new motherboard($storage3); $computer->read(); $computer->write(); $un_storage=new unknow(); $apdaterx=new Adpater($un_storage); $computer=new motherboard($apdaterx); $computer->read(); $computer->write(); ?>
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ