°Ë±¦Êé¿â > ÎÄѧÆäËûµç×ÓÊé > VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) >

µÚ62²¿·Ö

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

С˵£º VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) ×ÖÊý£º ÿҳ4000×Ö

°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡




helped¡¡me¡¡figure¡¡out¡¡a¡¡bug¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡TestInsert£¨£©¡¡method¡¡is¡¡an¡¡example¡¡of¡¡an¡¡exhaustive¡¡test¡¡of¡¡a¡¡context¡£¡¡The¡¡download

able¡¡source¡¡code¡¡contains¡¡several¡¡other¡¡examples¡¡of¡¡exhaustive¡¡tests¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡234¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

212¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡DEBUGGING¡¡AND¡¡TESTING¡¡TOOLS¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Some¡¡of¡¡you¡¡might¡¡be¡¡thinking¡¡that¡¡to¡¡figure¡¡out¡¡why¡¡a¡¡test¡¡failed£»¡¡you¡¡should¡¡use¡¡a¡¡debugger¡£¡¡However£»¡¡with¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡proper¡¡tests¡¡that¡¡are¡¡part¡¡of¡¡an¡¡extensive¡¡testing¡¡framework¡¡and¡¡that¡¡generate¡¡extensive¡¡output£»¡¡the¡¡need¡¡for¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡debugger¡¡is¡¡reduced¡£¡¡Among¡¡the¡¡people¡¡who¡¡believe¡¡in¡¡a¡¡test¡­driven¡¡development¡¡£¨TDD£©¡¡environment¡¡£¨including¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡me£©£»¡¡there¡¡is¡¡a¡¡question¡¡on¡¡the¡¡merits¡¡of¡¡a¡¡debugger¡£¡¡According¡¡to¡¡Wikipedia¡¯s¡¡Test¡­Driven¡¡Development¡¡entry¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨http£º//en¡£wikipedia¡£org/wiki/Test¡­driven_development£©£»¡¡¡°Programmers¡¡using¡¡pure¡¡TDD¡¡on¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡new¡¡£¨¡®greenfield¡¯£©¡¡projects¡¡report¡¡they¡¡only¡¡rarely¡¡feel¡¡the¡¡need¡¡to¡¡invoke¡¡a¡¡debugger¡£¡¡Used¡¡in¡¡conjunction¡¡with¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡Version¡¡control¡¡system£»¡¡when¡¡tests¡¡fail¡¡unexpectedly£»¡¡reverting¡¡the¡¡code¡¡to¡¡the¡¡last¡¡version¡¡that¡¡passed¡¡all¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tests¡¡may¡¡often¡¡be¡¡more¡¡productive¡¡than¡¡debugging¡£¡±¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡debugger¡¡is¡¡good¡¡for¡¡finding¡¡problems£»¡¡but¡¡bad¡¡for¡¡understanding¡¡the¡¡nature¡¡of¡¡the¡¡problem¡£¡¡Good¡¡tests¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡verify¡¡scenarios¡£¡¡The¡¡more¡¡scenarios£»¡¡the¡¡more¡¡tests£»¡¡and¡¡the¡¡more¡¡tested¡¡your¡¡code¡¡is¡£¡¡If¡¡a¡¡particular¡¡scenario¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡fails£»¡¡you¡¡know¡¡that¡¡you¡¡have¡¡a¡¡problem¡£¡¡And¡¡if¡¡everything¡¡was¡¡OK¡¡until¡¡you¡¡made¡¡a¡¡slight¡¡change¡¡that¡¡caused¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡tests¡¡to¡¡fail£»¡¡you¡¡know¡¡you¡¡have¡¡a¡¡problem¡£¡¡Test¡¡scripts¡¡are¡¡signposts¡¡that¡¡tell¡¡you¡¡what¡¡is¡¡working¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡what¡¡might¡¡not¡¡be¡¡working¡£¡¡By¡¡using¡¡a¡¡debugger£»¡¡you¡¡are¡¡often¡¡testing¡¡large¡¡chunks¡¡of¡¡code¡¡where¡¡you¡¡need¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡labor¡¡to¡¡find¡¡the¡¡bug¡£¡¡A¡¡debugger¡¡has¡¡its¡¡uses£»¡¡but¡¡when¡¡writing¡¡good¡¡tests¡¡in¡¡many¡¡scenarios£»¡¡you¡¡will¡¡rarely¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡need¡¡to¡¡use¡¡it¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡And¡¡speaking¡¡of¡¡writing¡¡tests£»¡¡as¡¡I¡¡noted¡¡in¡¡Chapter¡¡6£»¡¡in¡¡this¡¡book£»¡¡I¡¡could¡¡introduce¡¡a¡¡testing¡¡framework¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡like¡¡NUnit¡¡£¨http£º//nunit¡£org£©¡¡or¡¡Microsoft¡¡Visual¡¡Studio¡¡Team¡¡System¡¡£¨http£º//¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡msdn2¡£microsoft¡£/en¡­us/vstudio/default¡£aspx£©¡£¡¡When¡¡you¡¡are¡¡writing¡¡production¡¡code£»¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡probably¡¡use¡¡such¡¡a¡¡testing¡¡framework¡£¡¡Testing¡¡frameworks¡¡do¡¡not¡¡help¡¡you¡¡to¡¡write¡¡your¡¡tests£»¡¡but¡¡rather¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡help¡¡you¡¡by¡¡providing¡¡support¡¡code¡¡to¡¡generate¡¡errors£»¡¡log¡¡problems£»¡¡and¡¡indicate¡¡progress¡¡of¡¡the¡¡tests¡£¡¡Do¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡not¡¡get¡¡misled¡¡by¡¡tools¡¡that¡¡say¡¡they¡¡can¡¡write¡¡the¡¡tests¡¡for¡¡you¡£¡¡No¡¡tool¡¡can¡¡write¡¡your¡¡tests£»¡¡because¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡would¡¡imply¡¡the¡¡tool¡¡understands¡¡the¡¡context¡¡of¡¡your¡¡code¡£¡¡And¡¡since¡¡such¡¡a¡¡tool¡¡does¡¡not¡¡yet¡¡exist£»¡¡you¡¡will¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡need¡¡to¡¡write¡¡your¡¡own¡¡tests¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementing¡¡Room¡¡Groupings¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Room¡¡groupings¡¡are¡¡collections¡¡of¡¡rooms¡¡that¡¡fall¡¡into¡¡a¡¡specific¡¡organization¡£¡¡The¡¡idea¡¡behind¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡grouping¡¡is¡¡to¡¡perform¡¡group¡¡operations¡¡without¡¡having¡¡to¡¡explicitly¡¡examine¡¡a¡¡room¡¡before¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡performing¡¡an¡¡operation¡£¡¡For¡¡example£»¡¡in¡¡the¡¡case¡¡of¡¡the¡¡museum£»¡¡we¡¡don¡¯t¡¡need¡¡to¡¡figure¡¡out¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡whether¡¡a¡¡room¡¡is¡¡public¡¡or¡¡private¡¡each¡¡time¡¡a¡¡global¡¡operation¡¡is¡¡being¡¡performed¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡organization¡¡of¡¡the¡¡collection¡¡is¡¡that¡¡there¡¡can¡¡be¡¡multiple¡¡room¡¡groupings¡¡that¡¡are¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡linked¡¡together£»¡¡and¡¡within¡¡a¡¡grouping£»¡¡there¡¡are¡¡multiple¡¡rooms¡¡that¡¡can¡¡be¡¡grouped¡¡together¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡linked¡¡list¡¡structure¡¡has¡¡two¡¡levels¡¡and¡¡is¡¡coded¡¡as¡¡follows¡¡£¨in¡¡¡¡LibLightingSystem£©£º¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡RoomGrouping¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡BaseLinkedListItem¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Rooms¡¡As¡¡Room¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Description¡¡As¡¡String¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Room¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡BaseLinkedListItem¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ObjRoom¡¡As¡¡IRoom¡¡

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


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡235¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡213¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡class¡¡declaration¡¡Room¡¡represents¡¡an¡¡individual¡¡room¡£¡¡But¡¡notice¡¡how¡¡it¡¡derives¡¡from¡¡¡¡

BaseLinkedListItem£»¡¡which¡¡seems¡¡to¡¡imply¡¡that¡¡Room¡¡is¡¡actually¡¡many¡¡rooms¡£¡¡This¡¡is¡¡part¡¡of¡¡the¡¡¡¡

linked¡¡list¡¡implementation£»¡¡it¡¡is¡¡like¡¡a¡¡chain£»¡¡where¡¡the¡¡chain¡¡is¡¡created¡¡by¡¡individual¡¡links¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡RoomGrouping¡¡class¡¡has¡¡two¡¡data¡¡members£º¡¡Rooms£»¡¡which¡¡represents¡¡the¡¡list¡¡of¡¡rooms¡¡in¡¡¡¡

the¡¡grouping£»¡¡and¡¡Description£»¡¡which¡¡represents¡¡an¡¡easy¡­to¡­understand¡¡description¡¡of¡¡the¡¡¡¡

grouping¡£¡¡The¡¡single¡¡data¡¡member¡¡for¡¡Room¡¡is¡¡a¡¡reference¡¡to¡¡an¡¡¡¡IRoom¡¡interface¡¡instance¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡room¡¡groupings¡¡are¡¡managed¡¡by¡¡the¡¡¡¡LightingController¡¡class¡£¡¡An¡¡initial¡¡implemen

tation¡¡of¡¡¡¡LightingController¡¡is¡¡as¡¡follows£º¡¡



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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_roomGroupings¡¡As¡¡BaseLinkedListItem¡¡=¡¡New¡¡RoomGrouping£¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡When¡¡dealing¡¡with¡¡linked¡¡lists£»¡¡you¡¡have¡¡a¡¡problem£º¡¡which¡¡is¡¡the¡¡first¡¡element¡¡of¡¡a¡¡list£¿¡¡When¡¡¡¡

you¡¡use¡¡arrays£»¡¡an¡¡empty¡¡list¡¡of¡¡arrays¡¡is¡¡an¡¡array¡¡with¡¡no¡¡references¡£¡¡But¡¡there¡¡is¡¡an¡¡explicit¡¡¡¡

array¡¡object¡£¡¡Using¡¡the¡¡linked¡¡list£»¡¡an¡¡empty¡¡linked¡¡list¡¡is¡¡a¡¡list¡¡that¡¡does¡¡not¡¡exist¡£¡¡Thus£»¡¡when¡¡¡¡

you¡¡want¡¡to¡¡create¡¡a¡¡list£»¡¡you¡¡need¡¡a¡¡room¡£¡¡In¡¡¡¡LightingController£»¡¡the¡¡first¡¡element¡¡is¡¡an¡¡instance¡¡¡¡

of¡¡RoomGrouping£»¡¡which¡¡is¡¡not¡¡a¡¡room¡¡grouping£»¡¡but¡¡serves¡¡as¡¡a¡¡placeholder¡£¡¡To¡¡insert¡¡a¡¡room¡¡¡¡

grouping£»¡¡you¡¡could¡¡simply¡¡use¡¡this¡¡code£º¡¡



_roomGroupings¡£Insert£¨NewRoomGroup£¨£©£©¡¡



¡¡¡¡¡¡¡¡¡¡Without¡¡the¡¡placeholder£»¡¡you¡¡would¡¡need¡¡to¡¡write¡¡the¡¡following¡¡code¡¡whenever¡¡you¡¡¡¡

wanted¡¡to¡¡add¡¡an¡¡element¡¡into¡¡the¡¡list¡£¡¡



If¡¡_roomGroupings¡¡Is¡¡Nothing¡¡Then¡¡

¡¡¡¡¡¡¡¡_roomGroupings¡¡=¡¡NewRoomGroup£¨£©¡¡

Else¡¡¡¡

¡¡¡¡¡¡¡¡_roomGroupings¡£Insert£¨NewRoomGroup£¨£©£©¡¡

End¡¡If¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡code¡¡that¡¡uses¡¡the¡¡placeholder¡¡is¡¡shorter¡¡and¡¡simpler£»¡¡however£»¡¡it¡¡also¡¡requires¡¡a¡¡dangling¡¡¡¡

instance¡¡of¡¡RoomGrouping¡¡that¡¡has¡¡no¡¡real¡¡value¡£¡¡I¡¡chose¡¡the¡¡dangling¡¡approach¡¡because¡¡I¡¡am¡¡¡¡

making¡¡the¡¡decision¡¡that¡¡a¡¡room¡¡grouping¡¡with¡¡no¡¡identifier¡¡is¡¡the¡¡default¡¡room¡¡grouping¡£¡¡



Adding¡¡a¡¡Room¡¡Grouping¡¡



The¡¡following¡¡code¡¡adds¡¡a¡¡room¡¡grouping¡¡£¨added¡¡to¡¡the¡¡class¡¡¡¡LightingController£©¡£¡¡



¡¡¡¡¡¡¡¡Public¡¡Function¡¡AddRoomGrouping£¨ByVal¡¡description¡¡As¡¡String£©¡¡As¡¡Object¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡grouping¡¡As¡¡RoomGrouping¡¡=¡¡New¡¡RoomGrouping£¨£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡With¡¡£û¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£Description¡¡=¡¡description£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£Rooms¡¡=¡¡Nothing¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£ý¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_roomGroupings¡£Insert£¨grouping£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡grouping¡¡

¡¡¡¡¡¡¡¡End¡¡Function¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡236¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

214¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡add¡¡a¡¡new¡¡room¡¡grouping£»¡¡you¡¡instantiate¡¡RoomGrouping£»¡¡assign¡¡the¡¡data¡¡members£»¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡then¡¡call¡¡the¡¡method¡¡_roomGroupings¡£Insert£¨£©¡¡to¡¡insert¡¡the¡¡new¡¡room¡¡grouping¡¡into¡¡the¡¡linked¡¡list¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡look¡¡at¡¡the¡¡technique¡¡for¡¡assigning¡¡data¡¡members£»¡¡called¡¡object¡¡initialization¡£¡¡In¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡previous¡¡examples£»¡¡when¡¡an¡¡object¡¡was¡¡instantiated¡¡and¡¡we¡¡wanted¡¡to¡¡assign¡¡default¡¡values£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡we¡¡would¡¡create¡¡a¡¡constructor¡¡with¡¡the¡¡appropriate¡¡parameters¡£¡¡However£»¡¡another¡¡way¡¡is¡¡to¡¡instan

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tiate¡¡the¡¡object¡¡and¡¡define¡¡a¡¡block¡¡that¡¡assigns¡¡the¡¡appropriate¡¡data¡¡members¡¡or¡¡properties¡£¡¡In¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡case¡¡of¡¡RoomGrouping£»¡¡there¡¡are¡¡two¡¡publicly¡¡defined¡¡data¡¡members£º¡¡Description¡¡and¡¡Rooms£º¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£Description¡¡=¡¡description£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£Rooms¡¡=¡¡Nothing¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Description¡¡and¡¡¡¡Rooms¡¡data¡¡members¡¡have¡¡assign¡¡access£»¡¡which¡¡is¡¡important¡¡as¡¡this¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡technique¡¡only¡¡works¡¡with¡¡properties¡¡that¡¡are¡¡not¡¡read¡­only¡£¡¡To¡¡assign¡¡a¡¡data¡¡member¡¡or¡¡prop

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡erty£»¡¡after¡¡the¡¡object¡¡instantiation£»¡¡add¡¡the¡¡With¡¡keyword£»¡¡and¡¡then¡¡within¡¡curly¡¡brackets£»¡¡assign¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡each¡¡individual¡¡data¡¡member¡¡using¡¡a¡¡key/value¡¡pair£»¡¡in¡¡this¡¡form£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡With¡¡£û¡¡¡£Key1¡¡=¡¡value1£»¡¡¡£Key2¡¡=¡¡value2¡¡£ý¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡key¡¡represents¡¡the¡¡data¡¡member¡¡property¡¡to¡¡assign£»¡¡and¡¡the¡¡value¡¡is¡¡the¡¡data¡¡that¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡assigned¡¡to¡¡the¡¡data¡¡member¡¡or¡¡property¡£¡¡In¡¡the¡¡form¡¡example£»¡¡the¡¡properties¡¡Key1¡¡and¡¡¡¡Key2¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡set¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Another¡¡technique¡¡of¡¡interest¡¡in¡¡the¡¡code¡¡to¡¡add¡¡a¡¡room¡¡grouping¡¡is¡¡the¡¡definition¡¡of¡¡a¡¡data¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡handle¡¡when¡¡passing¡¡information£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡grouping¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡implementation¡¡of¡¡AddRoomGrouping£¨£©£»¡¡the¡¡variable¡¡grouping¡¡is¡¡assigned¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡instance¡¡of¡¡RoomGrouping¡£¡¡The¡¡declaration¡¡of¡¡the¡¡RoomGrouping¡¡class¡¡limits¡¡its¡¡scope¡¡to¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡LibLightingSystem¡¡assembly¡¡only£»¡¡while¡¡the¡¡declaration¡¡of¡¡¡¡LightingController¡¡is¡¡public¡£¡¡If¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡method¡¡AddRoomGrouping£¨£©¡¡had¡¡attempted¡¡to¡¡return¡¡an¡¡instance¡¡of¡¡RoomGrouping£»¡¡the¡¡piler¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡would¡¡have¡¡marked¡¡this¡¡as¡¡an¡¡error£»¡¡because¡¡the¡¡scope¡¡is¡¡inconsistent¡£¡¡Assuming¡¡for¡¡the¡¡moment¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡you¡¡did¡¡want¡¡to¡¡return¡¡an¡¡instance¡¡of¡¡RoomGrouping£»¡¡your¡¡only¡¡solution¡¡would¡¡be¡¡to¡¡declare¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡RoomGrouping¡¡as¡¡public¡£¡¡The¡¡declaration¡¡change¡¡is¡¡the¡¡wrong¡¡solution£»¡¡because¡¡RoomGrouping¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡class¡¡without¡¡declared¡¡methods¡¡£¨other¡¡than¡¡the¡¡base¡¡class¡¡methods£©¡¡and¡¡has¡¡public¡¡data¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡members¡£¡¡It¡¡is¡¡a¡¡class¡¡for¡¡a¡¡specific¡¡purpose¡¡and¡¡should¡¡not¡¡be¡¡shared¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Declaring¡¡RoomGrouping¡¡as¡¡public¡¡is¡¡the¡¡wrong¡¡approach£»¡¡so¡¡another¡¡solution¡¡is¡¡needed¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡could¡¡add¡¡a¡¡counter¡¡data¡¡member¡¡to¡¡the¡¡¡¡RoomGrouping¡¡declaration¡¡and¡¡return¡¡an¡¡Integer¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡value¡¡indicating¡¡the¡¡RoomGrouping¡¡instance¡¡you¡¡are

·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨0£© ²È£¨1£©

Äã¿ÉÄÜϲ»¶µÄ