Ô´ÂëÍø,Ô´ÂëÂÛ̳,Ô´ÂëÖ®¼Ò,ÉÌÒµÔ´Âë,ÓÎÏ·Ô´ÂëÏÂÔØ,discuz²å¼þ,ÆåÅÆÔ´ÂëÏÂÔØ,¾«Æ·Ô´ÂëÂÛ̳

 ÕÒ»ØÃÜÂë
 Á¢¼´×¢²á
²é¿´: 369|»Ø¸´: 17

[PHP±à³Ì] PHP ÔÓ̸¡¶Öع¹-¸ÄÉƼÈÓдúÂëµÄÉè¼Æ¡·Ö®¶þ ¶ÔÏóÖ®¼ä°áÒÆÌØÐÔ

[¸´ÖÆÁ´½Ó]

7Íò

Ö÷Ìâ

861

»ØÌû

32Íò

»ý·Ö

ÂÛ̳ԪÀÏ

Rank: 8Rank: 8

»ý·Ö
329525
·¢±íÓÚ 2012-4-9 22:20:50 | ÏÔʾȫ²¿Â¥²ã |ÔĶÁģʽ
³Ð½ÓÉÏÎÄPHP ÔÓ̸¡¶Öع¹-¸ÄÉƼÈÓдúÂëµÄÉè¼Æ¡·Ö® ÖØÐÂ×éÖ¯ÄãµÄº¯Êý £¬¼ÌÐø˵Öع¹·½ÃæµÄÄÚÈÝ Ë¼Î¬µ¼Í¼

Ë÷Òý£º

Ø Move Method£¨°áÒƺ¯Êý£© Ø Move Field £¨°áÒÆÖµÓò£© Ø Extract Class £¨ÌáÁ¶Àࣩ Ø Inline Class £¨½«ÀàÄÚÁª»¯£¬¾ÍÊǰѵ±Ç°µÄÀàºÏ²¢µ½ÆäËûÀàÖУ© Ø Hide Delegate £¨Òþ²ØίÍйØϵ£© Ø Remove Middle Man £¨ ÒƳýÖмäÈË£© Ø Introduce Foreign Method £¨ÒýÈëÍâ¼Óº¯Êý£© Ø Introduce Local Extension £¨ÒýÈë±¾µØÀ©Õ¹£©    ½éÉÜ    ³Ð½ÓÉÏÎÄPHP ÔÓ̸¡¶Öع¹-¸ÄÉƼÈÓдúÂëµÄÉè¼Æ¡·Ö® ÖØÐÂ×éÖ¯ÄãµÄº¯Êý £¬¼ÌÐø˵Öع¹·½ÃæµÄÄÚÈÝ¡£  
 ×¨ÒµÊõÓï   delegate£ºÎ¯ÍÐ encapsulate:·â×° introduce£ºÒýÈë wrapper£º¸²¸Ç    Ç°ÑÔ   ¡±¾ö¶¨°ÑÔðÈηÅÔÚÄÄÀï¡°¡ª¡ªÔËÓÃÖع¹¸Ä±äÔ­ÏȵÄÉè¼Æ¡£  

½âÊÍ£º

¡¡¡¡1¡¢Class³Ðµ£¹ý¶à¶øÓ·Öײ»¿°¡ª¡ªExtract Class½«Ò»²¿·ÖÔðÈηÖÀë³öÈ¥¡£

¡¡¡¡2¡¢ClassûÓге£×ã¹»¶àµÄÔðÈΣ¬²»ÔÙÓе¥¶À´æÔÚµÄÀíÓÉ¡ª¡ªInline Class½«ËüÈÚÈëÁíÒ»¸öClass¡£

¡¡¡¡3¡¢ClassʹÓÃÁíÒ»¸öClass¡ª¡ªHide DelegateÒþ²Ø¹Øϵ¡£

¡¡¡¡4¡¢³Ð½Ó£¨3£©£¬Èç¹ûClientͨ¹ýMiddle Man µ÷ÓúܶàµÄDelegate ClassµÄº¯Êý£¨ÕâÀïÖ»ÊǼòµ¥µ÷Óã¬Ö»×öÌøת£¬¶øMiddle ManûÓÐ×öÌ«¶àµÄÒµÎñÂß¼­£¬Èç10¸öDelegate ClassÖеÄMethod¶ÔÓ¦10¸öMiddle ManµÄMethod£©¡ª¡ªRemove Middle Man£¬Ö±½ÓʹÓÃDelegate Class£¬¿ÉÒÔ²¿·ÖʹÓÃDelegate Method¡£

 

 Move Method   Èç¹ûÒ»¸öÀàÖеķ½·¨ÓëÁíÒ»¸öÀàÓкܶàµÄ½»Á÷£¬ÄÇôÎÒÃǾÍÔÚÁíÒ»¸öÀàÖн¨Á¢Ò»¸öÓÐÀàËƹ¦ÄܵÄк¯Êý£¬½«¾Éº¯Êý±ä³ÉÒ»¸öµ¥´¿µÄDelegating Method£¬ »òÊǽ«¾Éº¯ÊýÒƳý¡£

 

Ààͼ:

 

¶¯»ú£º

¡¡¡¡1¡¢Èç¹ûÒ»¸öÀàÓëÁíÒ»¸öÀàÓи߶ÈñîºÏ£¬ÎҾͻáMove Method¡£¡ª¡ªclass¸ü¼òµ¥£¬¸ü¸É¾»ÀûÂäµÄʵÏÖϵͳ½»¸¶µÄÈÎÎñ¡£

¡¡¡¡2¡¢Òƶ¯Ò»Ð©ÖµÓò£¬¾ÍÒª¼ì²éÊÇ·ñʹÓÃÁíÒ»¸öÀàµÄ´ÎÊý±ØʹÓÃËùפ¶ÔÏóµÄ´ÎÊý»¹¶à¡£

 Move Field   ×´¿ö£ºÄãµÄclassÖеÄfield±»ÁíÒ»¸öclass¸ü¶àµÄÓõ½¡£ÄÇôÔÚÁíÒ»¸öclassÀィÁ¢new field£¬Ð޸ľɵÄfield¡£  

   Extract Class   ×´¿ö£ºÒ»¸öÀà×öÁËÁ½¸öÀà×öµÄÊ£¬ÄÇô½¨Á¢Ò»¸öÐÂClass£¬½«Ïà¹ØµÄFieldºÍMethod´Ó¾ÉClassÒƵ½ÐÂClass¡£

 

 

 Inline Class   ×´¿ö£ºÄãµÄij¸öClassûÓÐ×öÌ«¶àÊÂÇ飨ûÓге£×ã¹»ÔðÈΣ©£¬ÄÇô½«ClassµÄËùÓÐÌØÐÔ°áÒƵ½ÁíÒ»¸öClassÖУ¬È»ºóÒƳýÔ­Class¡£ ¶¯»ú£ºInline ClassÓëExtract ClassÏà·´¡£¡ª¡ª°ÑExtract ClassÀý×Ó·´¹ýÈ¥£¬ÒòΪPhoneNumberÖ»ÓÃ×÷¶ÁÈ¡codeºÍnumber¡£    Hide Delegate   ×´¿ö£º¿Í»§Ö±½Óµ÷ÓÃServer ObjectµÄDelegate ClassµÄMethod£¬ÄÇôÔÚServer¶Ë½¨Á¢¿Í»§ËùÐèµÄº¯ÊýMethod£¬ÓÃÒÔÒþ²ØίÍйØϵ¡£    Ñ§¹ý¶ÔÏó¼¼ÊõµÄÈ˶¼ÖªµÀ£¬ËäÈ»phpÔÊÐíÄ㽫fieldÉùÃ÷Ϊpublic£¬µ«Ä㻹Ӧ¸ÃÒþ²Øfield£¨private£©¡£Ëæמ­ÑéÈÕ½¥·á¸»£¬Óиü¶àÖµµÃ·â×°µÄ¶«Î÷¡£   ¿´ÏÂÃæÒ»¸öÀý×Ó£º

   $person->getDepartment()->getManager()Ã÷ÏÔ½Ò¶ÁË£¬ÒªÏëÕÒµ½XiaocaiµÄÁìµ¼£¬±ØÐëÒª¾­¹ýdepartment£¬ËùÒÔÎÒÃÇÒª×öµÄÊÂÒþ²Ødepartment¡£¡ª¡ª¿ÉÒÔ¼õÉÙñîºÏÐÔ¡£  

 

 Remove Middle Man   ×´¿ö£ºÈç¹ûij¸öClass×öÁ˹ý¶àµÄSimple Delegate£¬ÄÇôÎÒÃǾÍÖ±½Óµ÷ÓÃDelegate Class¡£ ¶¯»ú£ºÔÚHide DelegateÖеÄÀý×ÓÀïµ±DepartmentÓиü¶àз½·¨µÄʱºò£¬ÎÒÃÇΪÁËHide Delegate£¬¾ÍÒª±ØÐëÔÚPersonÀïÌí¼ÓÏàÓ¦µÄ·½·¨×öDelegateÖ®Óá£ÕâʱºòµÄPersonÍêÈ«±ä³ÉÁËÒ»¸öMiddle Man£¬´ËʱÎÒÃǾÍÓ¦¸ÃÖ±½Óµ÷ÓÃDelegate Class¡ª¡ªDepartment¡£  Öع¹µÄÒâÒå¾ÍÔÚÓÚ£ºÄãÓÀÔ¶²»±Ø˵¶Ô²»Æð£¬Ö»ÒªÄã°Ñ³öÎÊÌâµÄµØ·½ÐÞ²¹ºÃ¾ÍÐÐÁË¡£      

 

 Introduce Foreign Method   ×´¿ö£ºÓÐÒ»¸öÀàClientÐèҪʹÓõÄÀàPreviousEndÖÐÒ»¸ö¶îÍ⺯Êý£¬µ«ÄãÎÞ·¨ÐÞ¸ÄÕâ¸öÀàPreviousEnd£¬ÄÇôÄã¾ÍÔÚClientÖн¨Á¢Ò»¸öº¯Êý£¬²¢ÒÔÒ»¸öPreviousEndʵÌå×öΪ²ÎÊý¡£

 

 Introduce Local Extention   ×´¿ö£ºÄãµÄClassÐèҪһЩ¶îÍ⺯Êý£¬µ«Äã²»ÄÜÐ޸ĵ±Ç°µÄÀ࣬ÄÇô½¨Á¢Ò»¸öÐÂClass£¬Ê¹Ëü°üº¬ÕâЩº¯Êý¡£Ê¹ÓÃSubclass »ò Wrapper¡£¡ª¡ªÕâ¸öÒ»°ãÓÃÓÚÄãÎÞ·¨ÐÞ¸ÄÔ´ÂëµÄÇé¿öÏÂʹÓᣠ   ÄÃÉÏÃæIntroduce Foreign MethodÀý×ÓÀ´Ëµ

ʹÓÃSubclass·½·¨  

»òʹÓÃWrapper

 ×ܽá

  ÐèҪעÒâһϣ¬¡°Extract Class¡±ºÍ¡°Inline Class¡±£¬¡±Hide Delegate¡°ºÍ¡±Remove Middle Man"£¬¶¼ÊÇÏà·´µÄ¹ý³Ì£¬¾ßÌåÀí½â£¬¿ÉÒÔ¿´Ç°ÑÔÖеÄÄÇÕÅÁ÷³Ìͼ¡£   ¡°Hide Delegate"ÎÒÃdz£ÓÃÓÚʹÓÃÉÙÁ¿µÄ¡±Delegate Method¡°µÄʱºò£¬¶ø¡±Remove Middle Man¡°£¬ÓÃÓÚµ÷ÓúܶࡱDelegate Method¡°µÄʱºò£¬ÎÒÃÇ¿ÉÒÔÖ±½ÓʹÓÃDelegate Class£¬½øÐе÷Ó㬶øÓеÄDelegate MethodÎÒÃÇÊÓÇé¿ö±£ÁôÒ»²¿·Ö¡£   ¡°Extract Class¡±ºÍ¡°Inline Class¡±£¬"Extract Class"¾­³£ÓÃÓڳе£Äǹý¶àÔðÈζø±äµÃÓ·Öײ»¿°µÄClassÖУ¬¶ø¡°Inline Class¡±¾­³£ÓÃÓÚµ±Ç°µÄÕâ¸öÀࡱ̫²»¸ºÔðµÄ¡°Ê±ºòʹÓᣡª¡ªÎÒ¸öÈËÊÇÄþÔ¸¡°Extract Class¡±£¬Ò²²»Ô¸¡°Inline Class¡±¡£
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

9

Ö÷Ìâ

2Íò

»ØÌû

420

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
420
·¢±íÓÚ 2023-2-5 06:46:50 | ÏÔʾȫ²¿Â¥²ã
¸ø°Ö°Ö°Ö°Ö°Ö°Ö°Ö°Ö°Ö°Ö°Ë°Û°é°Ë°Û°é

1

Ö÷Ìâ

2Íò

»ØÌû

176

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
176
·¢±íÓÚ 2023-8-21 02:24:46 | ÏÔʾȫ²¿Â¥²ã
žžžÉúÅÂPSPÅÂ

16

Ö÷Ìâ

2Íò

»ØÌû

376

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
376
·¢±íÓÚ 2023-10-15 04:15:03 | ÏÔʾȫ²¿Â¥²ã
dfdsafdsfdsfdsf

0

Ö÷Ìâ

1Íò

»ØÌû

68

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
68
·¢±íÓÚ 2024-4-4 18:40:53 | ÏÔʾȫ²¿Â¥²ã
66666666666

2

Ö÷Ìâ

2Íò

»ØÌû

99

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
99
·¢±íÓÚ 2024-4-29 19:37:35 | ÏÔʾȫ²¿Â¥²ã
ÌìÌìÔ´ÂëÉçÇøÂÛ̳

0

Ö÷Ìâ

2Íò

»ØÌû

0

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
0
·¢±íÓÚ 2024-6-30 04:51:40 | ÏÔʾȫ²¿Â¥²ã
ÂÛ̳ÓÐÄã¸ü¾«²Ê£¡

2

Ö÷Ìâ

2Íò

»ØÌû

73

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
73
·¢±íÓÚ 2024-7-23 16:38:14 | ÏÔʾȫ²¿Â¥²ã
´ó¼Ò¶¼²»ÈÝÒ×£¡

2

Ö÷Ìâ

2Íò

»ØÌû

499

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
499
·¢±íÓÚ 2024-8-21 14:07:53 | ÏÔʾȫ²¿Â¥²ã
¶î·ç·ç·ç΢·ç΢·çÎ¥·¨

1

Ö÷Ìâ

2Íò

»ØÌû

307

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
307
·¢±íÓÚ 2024-8-30 15:40:59 | ÏÔʾȫ²¿Â¥²ã
vcxvcxv
¸ß¼¶Ä£Ê½
B Color Image Link Quote Code Smilies

±¾°æ»ý·Ö¹æÔò

ÊÖ»ú°æ|СºÚÎÝ|ÍøÕ¾µØͼ|Ô´ÂëÂÛ̳ ( º£Íâ°æ )

GMT+8, 2024-11-23 11:00 , Processed in 0.091622 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí