ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
¸»Ê¿¿µÐ¡ËµÍø ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ40²¿·Ö

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡


¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IRemoteControlRoom¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡IRoom¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡LightLevel£¨£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡LightSwitch£¨ByVal¡¡lightState¡¡As¡¡Boolean£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡DimLight£¨ByVal¡¡level¡¡As¡¡Double£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡only¡¡input¡¡that¡¡IRemoteControlRoom¡¡provides¡¡is¡¡information¡¡about¡¡whether¡¡the¡¡light¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡on£»¡¡off£»¡¡or¡¡at¡¡a¡¡certain¡¡level¡£¡¡This¡¡is¡¡through¡¡the¡¡¡¡LightLevel¡¡property¡£¡¡The¡¡¡¡LightLevel¡¡property¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡read¡­only£»¡¡because¡¡the¡¡controller¡¡and¡¡the¡¡light¡¡level¡¡might¡¡bee¡¡out¡¡of¡¡sync¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡example£»¡¡suppose¡¡it¡¯s¡¡time¡¡for¡¡the¡¡museum¡¡to¡¡close£»¡¡and¡¡the¡¡lights¡¡are¡¡switched¡¡off¡¡in¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡public¡­viewing¡¡area¡£¡¡But¡¡today£»¡¡the¡¡cleaners¡¡took¡¡a¡¡little¡¡while¡¡longer¡¡than¡¡usual¡£¡¡They¡¡turn¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡lights¡¡back¡¡on¡¡so¡¡that¡¡they¡¡can¡¡see¡¡what¡¡they¡¡are¡¡doing¡£¡¡The¡¡local¡¡device¡¡can¡¡do¡¡one¡¡of¡¡two¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡things£º¡¡allow¡¡the¡¡light¡¡to¡¡be¡¡turned¡¡on¡¡without¡¡the¡¡approval¡¡of¡¡the¡¡controller£»¡¡or¡¡not¡¡allow¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡light¡¡to¡¡be¡¡turned¡¡on£»¡¡requiring¡¡a¡¡controller¡¡intervention¡£¡¡The¡¡best¡¡approach¡¡is¡¡to¡¡allow¡¡a¡¡local¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡override¡¡and¡¡let¡¡the¡¡cleaners¡¡turn¡¡on¡¡the¡¡light¡£¡¡The¡¡LightLevel¡¡property¡¡is¡¡necessary¡¡so¡¡that¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡controller¡¡can¡¡verify¡¡if¡¡the¡¡state¡¡of¡¡the¡¡light¡¡is¡¡what¡¡the¡¡controller¡¡expects¡¡it¡¡to¡¡be¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡When¡¡you¡¡are¡¡defining¡¡a¡¡kernel£»¡¡sometimes¡¡it¡¡is¡¡necessary¡¡to¡¡add¡¡functionality¡¡into¡¡an¡¡interface¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡verifies¡¡the¡¡state¡¡of¡¡the¡¡implementation¡£¡¡Because¡¡the¡¡kernel¡¡is¡¡not¡¡in¡¡control¡¡of¡¡the¡¡implementation£»¡¡the¡¡kernel¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡should¡¡not¡¡assume¡¡the¡¡state£»¡¡as¡¡the¡¡state¡¡could¡¡change¡¡for¡¡some¡¡reason¡£¡¡In¡¡the¡¡case¡¡of¡¡the¡¡lighting¡¡system£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡change¡¡could¡¡be¡¡due¡¡to¡¡a¡¡cleaner¡¡turning¡¡on¡¡the¡¡light¡¡after¡¡it¡¡was¡¡turned¡¡off¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡225¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡8¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡T¡¡O¡¡R¡¡IE¡¡N¡¡TE¡¡D¡¡¡¡¡¡A¡¡R¡¡CH¡¡I¡¡TE¡¡C¡¡TU¡¡R¡¡E¡¡203¡¡



¡¡¡¡¡¡¡¡¡¡¡¡The¡¡¡¡IRemoteControlRoom¡¡methods¡¡¡¡LightSwitch£¨£©¡¡and¡¡DimLight£¨£©¡¡turn¡¡the¡¡light¡¡on¡¡or¡¡off¡¡¡¡

and¡¡set¡¡the¡¡light¡¡to¡¡a¡¡certain¡¡level£»¡¡respectively¡£¡¡These¡¡methods¡¡are¡¡used¡¡to¡¡control¡¡the¡¡state¡¡of¡¡¡¡

the¡¡implementation¡£¡¡



Defining¡¡the¡¡ISensorRoom¡¡Interface¡¡



Another¡¡type¡¡of¡¡room¡¡is¡¡one¡¡that¡¡can¡¡be¡¡controlled¡¡under¡¡certain¡¡circumstances¡£¡¡Let¡¯s¡¡go¡¡back¡¡¡¡

to¡¡the¡¡cleaner¡¡example¡¡where¡¡the¡¡cleaner¡¡turned¡¡on¡¡the¡¡light¡£¡¡If¡¡the¡¡controller¡¡notices¡¡that¡¡the¡¡¡¡

light¡¡is¡¡on£»¡¡even¡¡though¡¡it¡¡was¡¡turned¡¡off£»¡¡should¡¡the¡¡controller¡¡turn¡¡off¡¡the¡¡light£¿¡¡You¡¡might¡¡say¡¡¡¡

sure£»¡¡the¡¡controller¡¡should¡¡turn¡¡off¡¡the¡¡light¡£¡¡However£»¡¡that¡¡is¡¡not¡¡pletely¡¡correct¡£¡¡Imagine¡¡¡¡

the¡¡situation¡¡where¡¡the¡¡cleaner¡¡turns¡¡on¡¡the¡¡light¡¡and¡¡the¡¡controller¡¡turns¡¡it¡¡off¡£¡¡The¡¡cleaner¡¡would¡¡¡¡

immediately¡¡turn¡¡the¡¡light¡¡back¡¡on£»¡¡and¡¡the¡¡controller¡¡would¡¡turn¡¡it¡¡off¡£¡¡The¡¡cleaner¡¡would¡¡tape¡¡¡¡

the¡¡light¡¡switch¡¡down¡¡so¡¡that¡¡a¡¡constant¡¡battle¡¡of¡¡the¡¡light¡¡going¡¡on¡¡and¡¡off¡¡ensues¡¡£¨because¡¡this¡¡¡¡

battle¡¡is¡¡in¡¡milliseconds£»¡¡the¡¡light¡¡remains¡¡on£©¡£¡¡A¡¡smarter¡¡approach¡¡would¡¡be¡¡to¡¡allow¡¡a¡¡timing¡¡¡¡

of¡¡the¡¡light¡£¡¡But¡¡how¡¡much¡¡time¡ªa¡¡quarter¡¡of¡¡an¡¡hour£»¡¡a¡¡half¡¡hour£»¡¡an¡¡hour£¿¡¡

¡¡¡¡¡¡¡¡¡¡Another¡¡approach¡¡is¡¡not¡¡to¡¡use¡¡a¡¡time¡¡interval£»¡¡but¡¡to¡¡enhance¡¡the¡¡interface¡¡and¡¡allow¡¡the¡¡¡¡

controller¡¡to¡¡figure¡¡out¡¡the¡¡state¡£¡¡This¡¡enhanced¡¡interface£»¡¡called¡¡ISensorRoom£»¡¡is¡¡defined¡¡as¡¡¡¡

follows¡¡£¨in¡¡LibLightingSystem£©£º¡¡



Public¡¡Interface¡¡ISensorRoom¡¡¡¡

¡¡¡¡¡¡¡¡Inherits¡¡IRemoteControlRoom¡¡

¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡IsPersonInRoom£¨£©¡¡As¡¡Boolean¡¡

End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡The¡¡¡¡ISensorRoom¡¡interface¡¡has¡¡a¡¡single¡¡property¡¡IsPersonInRoom£»¡¡which¡¡is¡¡a¡¡Boolean¡¡prop

erty¡£¡¡If¡¡the¡¡property¡¡has¡¡a¡¡value¡¡of¡¡True£»¡¡then¡¡a¡¡person¡¡is¡¡in¡¡the¡¡room£»¡¡otherwise£»¡¡no¡¡person¡¡is¡¡in¡¡¡¡

the¡¡room¡£¡¡How¡¡the¡¡implementation¡¡determines¡¡whether¡¡or¡¡not¡¡a¡¡person¡¡is¡¡in¡¡the¡¡room¡¡is¡¡not¡¡¡¡

the¡¡problem¡¡of¡¡the¡¡kernel¡£¡¡The¡¡kernel¡¡assumes¡¡the¡¡implementation¡¡knows¡¡how¡¡to¡¡figure¡¡this¡¡¡¡

out¡£¡¡¡¡



¡öNote¡¡¡¡As¡¡a¡¡general¡¡rule¡¡of¡¡thumb£»¡¡the¡¡kernel¡¡can¡¡municate¡¡with¡¡the¡¡implementation¡¡only¡¡via¡¡the¡¡inter

face¡£¡¡The¡¡kernel¡¡should¡¡never¡¡assume¡¡a¡¡certain¡¡implementation¡¡of¡¡an¡¡interface¡£¡¡The¡¡kernel¡¡should¡¡take¡¡the¡¡¡¡

approach¡¡that¡¡what¡¡it¡¡sees¡¡is¡¡what¡¡it¡¡gets¡£¡¡Thus£»¡¡if¡¡the¡¡kernel¡¡needs¡¡additional¡¡information£»¡¡the¡¡interface¡¡¡¡

should¡¡be¡¡extended¡¡during¡¡design£»¡¡or¡¡another¡¡interface¡¡should¡¡be¡¡implemented¡£¡¡Of¡¡course£»¡¡this¡¡does¡¡not¡¡mean¡¡¡¡

for¡¡every¡¡piece¡¡of¡¡state¡¡the¡¡interface¡¡should¡¡be¡¡extended¡£¡¡Sometimes£»¡¡you¡¡will¡¡need¡¡to¡¡define¡¡a¡¡specific¡¡inter

face£»¡¡such¡¡as¡¡in¡¡the¡¡tax¡¡application¡¡example¡¡in¡¡the¡¡previous¡¡chapter¡¡£¨¡¡ICanadianTaxEngine£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡that¡¡we¡¯ve¡¡created¡¡the¡¡interfaces£»¡¡we¡¯re¡¡ready¡¡to¡¡implement¡¡the¡¡kernel¡£¡¡



Implementing¡¡the¡¡Kernel¡¡



In¡¡this¡¡example£»¡¡the¡¡kernel¡¡will¡¡be¡¡a¡¡single¡¡class¡¡that¡¡contains¡¡all¡¡of¡¡the¡¡functionality¡¡of¡¡the¡¡¡¡

controller¡£¡¡This¡¡definition¡¡means¡¡that¡¡the¡¡individual¡¡implementations£»¡¡testing£»¡¡and¡¡applica

tions¡¡will¡¡interact¡¡with¡¡a¡¡single¡¡class¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡226¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

204¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡8¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TO¡¡R¡¡IE¡¡N¡¡T¡¡E¡¡D¡¡¡¡AR¡¡C¡¡HI¡¡TE¡¡CT¡¡U¡¡R¡¡E¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Here¡¡is¡¡an¡¡example¡¡of¡¡implementing¡¡the¡¡light¡­dimming¡¡method¡¡using¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡LightingController¡¡class¡¡£¨in¡¡¡¡LibLightingSystem£©£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡LightingController¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡DimLights£¨ByVal¡¡grouping¡¡As¡¡Object£»¡¡ByVal¡¡level¡¡As¡¡Double£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡user¡¡of¡¡¡¡LightingController¡¡would¡¡dim¡¡a¡¡light¡¡using¡¡this¡¡code£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡controller¡¡As¡¡LightingController¡¡=¡¡New¡¡LightingController£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡grouping¡¡As¡¡Object¡¡=¡¡Nothing¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡controller¡£DimLights£¨grouping£»¡¡0¡£50£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡user¡¡code¡¡instantiates¡¡the¡¡type¡¡¡¡LightingController¡¡directly¡¡and¡¡uses¡¡the¡¡method¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡DimLights£¨£©¡¡directly¡£¡¡Using¡¡classes¡¡directly¡¡has¡¡the¡¡cost¡¡that¡¡the¡¡controller¡¡code¡¡cannot¡¡change¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡without¡¡affecting¡¡the¡¡users£»¡¡as¡¡there¡¡is¡¡a¡¡tight¡¡coupling¡¡between¡¡the¡¡user¡¡code¡¡and¡¡the¡¡kernel¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡And¡¡this¡¡is¡¡why¡¡I¡¡have¡¡been¡¡writing¡¡at¡¡length¡¡about¡¡using¡¡interfaces£»¡¡ideas£»¡¡and¡¡implementa

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tions¡£¡¡Yet£»¡¡the¡¡controller¡¡appears¡¡to¡¡throw¡¡all¡¡of¡¡that¡¡out¡¡of¡¡the¡¡window¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡reason¡¡for¡¡using¡¡a¡¡class¡¡goes¡¡back¡¡to¡¡the¡¡previous¡¡chapter¡¯s¡¡example¡¡and¡¡the¡¡interfaces¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ITaxDeduction¡¡and¡¡¡¡ITaxIne¡£¡¡That¡¡example¡¡had¡¡only¡¡a¡¡single¡¡implementation¡¡of¡¡each¡¡inter

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡face£»¡¡and¡¡those¡¡implementations¡¡were¡¡not¡¡going¡¡to¡¡change¡£¡¡As¡¡I¡¡explained¡¡in¡¡the¡¡previous¡¡chapter£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡interfaces¡¡could¡¡have¡¡been¡¡represented¡¡as¡¡classes¡£¡¡The¡¡same¡¡logic¡¡applies¡¡with¡¡respect¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡controller¡£¡¡The¡¡controller¡¡is¡¡not¡¡going¡¡to¡¡change¡¡much¡¡from¡¡a¡¡method¡¡and¡¡property¡¡signature¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡perspective£»¡¡and¡¡there¡¡is¡¡going¡¡to¡¡be¡¡only¡¡a¡¡single¡¡implementation¡¡of¡¡the¡¡controller¡£¡¡Therefore£»¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡¡is¡¡not¡¡necessary¡£¡¡Using¡¡a¡¡class¡¡is¡¡pletely¡¡acceptable£»¡¡and¡¡it¡¯s¡¡the¡¡approach¡¡we¡¯re¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡using¡¡in¡¡this¡¡chapter¡£¡¡However£»¡¡I¡¯ll¡¡talk¡¡about¡¡when¡¡you¡¡might¡¡want¡¡to¡¡implement¡¡the¡¡kernel¡¡as¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡an¡¡interface¡¡a¡¡little¡¡later¡¡in¡¡the¡¡chapter£»¡¡in¡¡the¡¡¡°Defining¡¡the¡¡Kernel¡¡As¡¡an¡¡Interface¡¡Instead¡¡of¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡±¡¡section¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡controller¡¡represents¡¡a¡¡building¡¡that¡¡has¡¡the¡¡ability¡¡to¡¡organize¡¡rooms¡¡into¡¡groupings¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Based¡¡on¡¡the¡¡groupings£»¡¡the¡¡controller¡¡can¡¡perform¡¡operations¡¡such¡¡as¡¡turning¡¡the¡¡lights¡¡on¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡off£»¡¡or¡¡setting¡¡lights¡¡to¡¡a¡¡specific¡¡dimness¡£¡¡When¡¡each¡¡of¡¡these¡¡operations¡¡is¡¡executed£»¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡controller¡¡must¡¡respect¡¡the¡¡intentions¡¡of¡¡the¡¡individual¡¡rooms£»¡¡by¡¡querying¡¡for¡¡a¡¡particular¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡¡as¡¡defined¡¡by¡¡the¡¡previous¡¡section¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡controller¡¡has¡¡two¡¡main¡¡responsibilities£º¡¡calling¡¡the¡¡appropriate¡¡interface¡¡methods¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡organizing¡¡the¡¡interface¡¡instances¡£¡¡The¡¡organization¡¡of¡¡the¡¡instances¡¡involves¡¡using¡¡collec

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tions£»¡¡arrays£»¡¡or¡¡a¡¡linked¡¡list¡£¡¡We¡¯ll¡¡use¡¡a¡¡linked¡¡list¡¡in¡¡this¡¡example¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Storing¡¡a¡¡Collection¡¡Using¡¡a¡¡Linked¡¡List¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡examples¡¡in¡¡previous¡¡chapters£»¡¡we¡¡created¡¡a¡¡collection¡¡of¡¡objects¡¡using¡¡an¡¡array£»¡¡like¡¡this£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡array¡¡As¡¡MyType£¨£©¡¡=¡¡New¡¡MyType£¨9£©¡¡£û¡¡£ý¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡array£¨0£©¡¡=¡¡New¡¡MyType£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡array£¨2£©¡¡=¡¡New¡¡MyType£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡creates¡¡an¡¡array¡¡that¡¡can¡¡contain¡¡10¡¡elements¡¡at¡¡most¡¡£¨MyType£¨9£©£©¡£¡¡If¡¡you¡¡needed¡¡to¡¡store¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡20¡¡elements£»¡¡you¡¡would¡¡need¡¡to¡¡use¡¡the¡¡ReDim¡¡keyword¡¡with¡¡Preserve¡¡£¨as¡¡explained¡¡in¡¡Chapter¡¡4£©¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Another¡¡feature¡¡of¡¡an¡¡array¡¡is¡¡that¡¡you¡¡don¡¯t¡¡need¡¡to¡¡assign¡¡the¡¡elements¡¡in¡¡a¡¡sequential¡¡manner¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡example¡¡assigns¡¡the¡¡first¡¡and¡¡third¡¡positions£»¡¡with¡¡the¡¡second¡¡position¡¡being¡¡Nothing¡£¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡227¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡8¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡T¡¡O¡¡R¡¡IE¡¡N¡¡TE¡¡D¡¡¡¡¡¡A¡¡R¡¡CH¡¡I¡¡TE¡¡C¡¡TU¡¡R¡¡E¡¡205¡¡



Thus£»¡¡some¡¡code¡¡that¡¡iterates¡¡the¡¡array¡¡will¡¡need¡¡to¡¡verify¡¡that¡¡the¡¡array¡¡element¡¡is¡¡not¡¡Nothing¡£¡¡¡¡

The¡¡sample¡¡code¡¡generates¡¡the¡¡structure¡¡illustrated¡¡in¡¡Figure¡¡8¡­2¡£¡¡



Figure¡¡8¡­2¡£¡¡Array¡¡structure¡¡of¡¡referenced¡¡elements¡¡



¡¡¡¡¡¡¡¡¡¡Figure¡¡8¡­2¡¡reveals¡¡a¡¡very¡¡important¡¡aspect¡¡of¡¡reference¡¡types£º¡¡an¡¡array¡¡holds¡¡a¡¡reference¡¡to¡¡¡¡

the¡¡object¡¡and¡¡not¡¡the¡¡value¡¡of¡¡the¡¡object¡£¡¡If¡¡the¡¡array¡¡were¡¡value¡¡types£»¡¡then¡¡the¡¡entire¡¡value¡¡¡¡

would¡¡be¡¡stored¡¡in¡¡the¡¡array¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡array¡¡could¡¡just¡¡as¡¡easily¡¡have¡¡been¡¡some¡¡object¡¡with¡¡a¡¡number¡¡of¡¡variables£»¡¡like¡¡this£º¡¡



Class¡¡MyTypeArray¡¡

¡¡¡¡¡¡¡¡Public¡¡Element1¡¡As¡¡MyType¡¡

¡¡¡¡¡¡¡¡Public¡¡Element2¡¡As¡¡MyType¡¡

¡£¡¡¡£¡¡¡£¡¡

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡Since¡¡array¡¡elements¡¡are¡¡a¡¡bunch¡¡of¡¡references¡¡stored¡¡in¡¡a¡¡type£»¡¡you¡¡could¡¡make¡¡use¡¡of¡¡this¡¡¡¡

knowledge¡¡to¡¡create¡¡a¡¡type¡¡that¡¡serves¡¡no¡¡other¡¡purpose¡¡than¡¡referencing¡¡a¡¡list¡¡of¡¡elements£»¡¡¡¡

more¡¡monly¡¡called¡¡a¡¡linked¡¡list¡£¡¡

¡¡¡¡¡¡¡¡¡¡In¡¡a¡¡linked¡¡list£»¡¡the¡¡individual¡¡objects¡¡are¡¡linked¡¡together¡¡and¡¡reference¡¡another¡¡element¡¡¡¡

nearby¡£¡¡A¡¡doubly¡¡linked¡¡list¡¡will¡¡only¡¡ever¡¡hold¡¡references¡¡to¡¡two¡¡other¡¡objects£º¡¡the¡¡next¡¡one¡¡and¡¡¡¡

the¡¡previous¡¡one¡£¡¡£¨Another¡¡type¡¡is¡¡a¡¡singly¡¡linked¡¡list£»¡¡which¡¡holds¡¡a¡¡reference¡¡to¡¡only¡¡one¡¡other¡¡¡¡

object£º¡¡the¡¡next¡¡one¡££©¡¡

¡¡¡¡¡¡¡¡¡¡In¡¡a¡¡doubly¡¡linked¡¡list£»¡¡the¡¡type¡¡will¡¡have¡¡data¡¡members¡¡named¡¡NextItem¡¡and¡¡¡¡PrevItem¡£¡¡¡¡

Each¡¡of¡¡these¡¡data¡¡members¡¡is¡¡used¡¡to¡¡reference¡¡another¡¡element¡¡in¡¡the¡¡list£»¡¡as¡¡illustrated¡¡in¡¡¡¡

Figure¡¡8¡­3¡£¡¡To¡¡iterate¡¡a¡¡list£»¡¡you¡¡start¡¡from¡¡either¡¡the¡¡left¡¡or¡¡right¡¡side¡¡and¡¡then¡¡go¡¡to¡¡the¡¡NextItem¡¡¡¡

or¡¡PrevItem¡¡data¡¡members£»¡¡respectively¡£¡¡Here¡¡is¡¡an¡¡example£º¡¡



Dim¡¡curr¡¡As¡¡MyType¡¡=¡¡GetHeadOfList£¨£©¡¡

Do¡¡While¡¡£¨curr¡¡IsNot¡¡Nothing£©¡¡

¡¡¡¡¡¡¡¡'¡¡Do¡¡something¡¡with¡¡curr¡¡

¡¡¡¡¡¡¡¡curr¡¡=¡¡curr¡£NextItem¡¡

Loop¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡228¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

206¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡8¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TO¡¡R¡¡IE¡¡N¡¡T¡¡E¡¡D¡¡¡¡AR¡¡C¡¡HI¡¡TE¡¡CT¡¡U¡¡R¡¡E¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡8¡­3¡£¡¡Structure¡¡of¡¡doubly¡¡linked¡¡list¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡you¡¡can¡¡see£»¡¡you¡¡can¡¡easily¡¡add¡¡elements¡¡to¡¡linked¡¡lists¡£¡¡The¡¡drawback¡¡is¡¡that¡¡it¡¡is¡¡expensive¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡find¡¡a¡¡particular¡¡object£»¡¡as¡¡that¡¡requires¡¡iterating¡¡through¡¡the¡¡list¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡For¡¡the¡¡most¡¡part£»¡¡you¡¡will¡¡be¡¡using¡¡the¡¡standard¡¡¡¡List¡¡class£»¡¡but¡¡there¡¡is¡¡also¡¡a¡¡¡¡LinkedList¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡class¡£¡¡If¡¡you¡¯re¡¡interested£»¡¡you¡¡can¡¡find¡¡information¡¡about¡¡the¡¡¡¡version¡¡of¡¡System¡£Collection¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Generics¡£LinkedList¡¡in¡¡the¡¡MSDN¡¡documentation¡£¡¡We¡¯ll¡¡make¡¡our¡¡own¡¡linked¡¡list¡¡to¡¡demonstrate¡¡Visual¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Basic¡¡programming¡¡techniques£»¡¡but¡¡you¡¡should¡¡use¡¡the¡¡standard¡¡collection¡¡classes¡¡in¡¡almost¡¡every¡¡case¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡our¡¡application¡¯s¡¡kernel£»¡¡we¡¯ll¡¡use¡¡a¡¡doubly¡¡linked¡¡list¡¡to¡¡link¡¡together¡¡a¡¡number¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡rooms¡¡into¡¡a¡¡set¡¡of¡¡groupings¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Creating¡¡a¡¡Linked¡¡List¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡initial¡¡structure¡¡of¡¡the¡¡BaseLinkedListItem¡¡class¡¡is¡¡as¡¡follows¡¡£¨defined¡¡in¡¡¡¡LibLightingSystem£©£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡MustInherit¡¡Class¡¡BaseLinkedListItem¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_next¡¡As¡¡BaseLinkedListItem¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_prev¡¡As¡¡BaseLinkedListItem¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡NextItem£¨£©¡¡As¡¡BaseLinkedListItem¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_next¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡PrevItem£¨£©¡¡As¡¡BaseLinkedListItem¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_prev¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡BaseLinkedListItem¡¡is¡¡declared¡¡as¡¡MustInherit¡¡to¡¡indicate¡¡that¡¡using¡¡this¡¡class¡¡implies¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡must¡¡derive¡¡a¡¡class¡£¡¡¡¡PrevItem¡¡and¡¡NextItem¡¡are¡¡Visual¡¡Basic¡¡properties¡¡that¡¡can¡¡only¡¡read¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡values¡¡of¡¡the¡¡private¡¡data¡¡members¡¡of¡¡_prev¡¡and¡¡_next¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡229¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡8¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡T¡¡O¡¡R¡¡IE¡¡N¡¡TE¡¡D¡¡¡¡¡¡A¡¡R¡¡CH¡¡I¡¡TE¡¡C¡¡TU¡¡R¡¡E¡¡207¡¡



Inserting¡¡and¡¡Removing¡¡Linked¡¡List¡¡Items¡¡



Inserting¡¡an¡¡object¡¡into¡¡a¡¡linked¡¡list¡¡or¡¡removing¡¡an¡¡object¡¡from¡¡a¡¡linked¡¡list¡¡requires¡¡some¡¡¡¡

careful¡¡coding¡£¡¡You¡¡need¡¡to¡¡make¡¡sure¡¡that¡¡the¡¡actions¡¡will¡¡not¡¡corrupt¡¡the¡¡list¡£¡¡This¡¡is¡¡not¡¡a¡¡task¡¡¡¡

that¡¡you¡¡want¡¡to¡¡delegate¡¡to¡¡the¡¡users¡¡of¡¡the¡¡linked¡¡list£»¡¡as¡¡they¡¡could¡¡unintentionally¡¡corrupt¡¡¡¡

the¡¡list¡£¡¡The¡¡following¡¡is¡¡the¡¡code¡¡to¡¡insert¡¡and¡¡remove¡¡an¡¡object¡¡from¡¡a¡¡linked¡¡list£»¡¡and¡¡is¡¡part¡¡¡¡

of¡¡the¡¡BaseLinkedListItem¡¡class¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Insert£¨ByVal¡¡item¡¡As¡¡BaseLinkedListItem£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡item¡£_next¡¡=¡¡_next¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡item¡£_prev¡¡=¡¡Me¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_next¡¡IsNot¡¡Nothing¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_next¡£_prev¡¡=¡¡item¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_next¡¡=¡¡item¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Remove£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_next¡¡IsNot¡¡Nothing¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_next¡£_prev¡¡=¡¡_prev¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_prev¡¡IsNot¡¡Nothing¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_prev¡£_next¡¡=¡¡_next¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_next¡¡=¡¡Nothing¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_prev¡¡=¡¡Nothing¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡Insert£¨£©¡¡method¡¡assumes¡¡that¡¡you¡¡want¡¡to¡¡insert¡¡an¡¡object¡¡into¡¡the¡¡head¡¡of¡¡a¡¡list£»¡¡which¡¡¡¡

has¡¡at¡¡least¡¡one¡¡element¡£¡¡The¡¡Insert£¨£©¡¡method¡¡assumes¡¡the¡¡following¡¡code¡¡at¡¡a¡¡minimum¡£¡¡



Dim¡¡singleElement¡¡As¡¡BaseLinkedListItem¡¡=¡¡GetHeadOfList£¨£©¡¡

Dim¡¡anotherElement¡¡as¡¡BaseLinkedListItem¡¡=¡¡CreateListElement£¨£©¡¡

singleElement¡£Insert£¨anotherElement£©¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡first¡¡step¡¡is¡¡to¡¡assign¡¡the¡¡data¡¡members¡¡£¨_next£»¡¡_prev£©¡¡of¡¡the¡¡object¡¡£¨¡¡item£©¡¡that¡¡is¡¡going¡¡¡¡

to¡¡be¡¡added¡¡to¡¡the¡¡list¡£¡¡



¡öNote¡¡¡¡Notice¡¡how¡¡in¡¡the¡¡Insert£¨£©¡¡method£»¡¡it¡¡is¡¡possible¡¡to¡¡assign¡¡the¡¡private¡¡data¡¡members¡¡of¡¡another¡¡¡¡

object¡¡instance¡£¡¡You¡¡learned¡¡that¡¡private¡¡scope¡¡means¡¡that¡¡only¡¡the¡¡declared¡¡type¡¡can¡¡read¡¡private¡¡properties¡¡¡¡

and¡¡methods¡£¡¡This¡¡rule¡¡has¡¡not¡¡been¡¡violated£»¡¡because¡¡the¡¡rule¡¡implies¡¡types¡¡can¡¡read¡¡the¡¡private¡¡data¡¡member
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨11£© ²È£¨11£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡