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

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

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



pointless¡£¡¡The¡¡AndAlso¡¡operator¡¡used¡¡in¡¡place¡¡of¡¡And¡¡says¡¡if¡¡a¡¡does¡¡not¡¡equal¡¡b£»¡¡then¡¡stop¡¡processing¡¡¡¡

and¡¡move¡¡to¡¡the¡¡next¡¡piece¡¡of¡¡code¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡real¡¡question¡¡is¡¡why¡¡make¡¡the¡¡difference¡¡between¡¡AndAlso¡¡and¡¡And£¿¡¡I¡¡can¡¡only¡¡postu

late£»¡¡but¡¡in¡¡the¡¡early£»¡¡early¡¡days¡¡of¡¡Visual¡¡Basic£»¡¡programmers¡¡used¡¡to¡¡write¡¡code¡¡like¡¡this£º¡¡



If¡¡a¡¡=¡¡b¡¡And¡¡b¡¡=¡¡code¡£NextStatement£¨£©¡¡Then¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡method¡¡NextStatement£¨£©¡¡not¡¡only¡¡verifies¡¡state£»¡¡but¡¡also¡¡modifies¡¡state¡£¡¡If¡¡a¡¡did¡¡not¡¡¡¡

equal¡¡b£»¡¡then¡¡the¡¡state¡¡was¡¡not¡¡modified¡£¡¡And¡¡that¡¡was¡¡a¡¡problem£»¡¡since¡¡some¡¡programmers¡¡¡¡

relied¡¡on¡¡the¡¡fact¡¡that¡¡the¡¡other¡¡piece¡¡of¡¡code¡¡would¡¡be¡¡called¡¡regardless¡¡of¡¡how¡¡it¡¡was¡¡used¡£¡¡¡¡

Think¡¡about¡¡this¡¡logically£»¡¡and¡¡you¡¯ll¡¡see¡¡it¡¡is¡¡not¡¡incorrect¡£¡¡After¡¡all£»¡¡what¡¡is¡¡the¡¡difference¡¡¡¡

between¡¡the¡¡following¡¡two¡¡pieces¡¡of¡¡code£¿¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡132¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

110¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡D¡¡AT¡¡A¡¡¡¡S¡¡TR¡¡U¡¡CT¡¡U¡¡R¡¡E¡¡S£»¡¡¡¡¡¡DE¡¡CI¡¡SI¡¡ON¡¡S£»¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡L¡¡O¡¡OP¡¡S¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡b¡¡=¡¡code¡£NextStatement£¨£©¡¡and¡¡a¡¡=¡¡b¡¡Then¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡¡¡b¡¡=¡¡code¡£NextStatement£¨£©¡¡Then¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡answer¡¡is¡¡nothing£»¡¡but¡¡if¡¡And¡¡behaved¡¡like¡¡AndAlso¡¡by¡¡default£»¡¡then¡¡you¡¡would¡¡get¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡inconsistent¡¡state¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Preventing¡¡Repetition¡¡in¡¡the¡¡Route¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡¡¡FindNextLeg£¨£©¡¡method¡¡calls¡¡the¡¡CanContinue£¨£©¡¡method£»¡¡which¡¡is¡¡designed¡¡to¡¡halt¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡search¡£¡¡In¡¡the¡¡case¡¡of¡¡our¡¡depth¡­first¡¡search¡¡algorithm£»¡¡the¡¡purpose¡¡is¡¡to¡¡not¡¡fly¡¡to¡¡the¡¡same¡¡city¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡twice¡£¡¡Contained¡¡within¡¡the¡¡function¡¡is¡¡code¡¡similar¡¡to¡¡FindNextLeg£¨£©£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡Function¡¡CanContinueSearch£¨ByVal¡¡returnArray¡¡As¡¡Node£¨£©£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡city¡¡As¡¡Node£©¡¡As¡¡Boolean¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡c1¡¡As¡¡Integer¡¡=¡¡0¡¡To¡¡¡¡returnArray¡£Length¡¡1¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡returnArray£¨c1£©¡¡IsNot¡¡Nothing¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡returnArray£¨c1£©¡£CityName¡£pareTo£¨city¡£CityName£©¡¡=¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡False¡¡

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

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡True¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡logic¡¡is¡¡that¡¡CanContinueSearch£¨£©¡¡will¡¡iterate¡¡through¡¡the¡¡returnArray¡¡and¡¡see¡¡if¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡city¡¡being¡¡considered¡¡£¨variable¡¡city£©¡¡is¡¡already¡¡in¡¡the¡¡found¡¡path¡£¡¡If¡¡the¡¡city¡¡is¡¡in¡¡the¡¡path£»¡¡then¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡we¡¡stop¡¡searching¡¡that¡¡part¡¡of¡¡the¡¡tree£»¡¡otherwise£»¡¡we¡¡continue¡¡searching¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Running¡¡the¡¡Depth¡­First¡¡Search¡¡Algorithm¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Everything¡¡has¡¡been¡¡implemented£»¡¡including¡¡tests£»¡¡so¡¡we¡¡are¡¡ready¡¡to¡¡run¡¡the¡¡test¡¡of¡¡finding¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡flight¡¡between¡¡Montreal¡¡and¡¡Seattle¡£¡¡Looking¡¡at¡¡Figure¡¡4¡­2£»¡¡you¡¡can¡¡see¡¡two¡¡paths£º¡¡Montreal¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡Los¡¡Angeles¡¡to¡¡Seattle£»¡¡or¡¡Montreal¡¡to¡¡Toronto¡¡to¡¡Seattle¡£¡¡However£»¡¡running¡¡the¡¡algorithm¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡generates¡¡the¡¡following¡¡peculiar¡¡result¡¡£¨you¡¡have¡¡not¡¡seen¡¡how¡¡to¡¡display¡¡the¡¡results£»¡¡but¡¡that¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡done¡¡easily¡¡enough¡¡with¡¡a¡¡For¡¡loop¡¡that¡¡iterates¡¡over¡¡foundRoute£©£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Montreal¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡New¡¡York¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Houston¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Miami¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Toronto¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Seattle¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡133¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡D¡¡AT¡¡A¡¡¡¡S¡¡TR¡¡U¡¡CT¡¡U¡¡R¡¡E¡¡S£»¡¡¡¡¡¡DE¡¡CI¡¡SI¡¡ON¡¡S£»¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡L¡¡O¡¡OP¡¡S¡¡111¡¡



¡¡¡¡¡¡¡¡¡¡Looking¡¡at¡¡the¡¡result£»¡¡you¡¡are¡¡probably¡¡thinking¡¡that¡¡the¡¡algorithm¡¡does¡¡not¡¡work£»¡¡because¡¡¡¡

the¡¡proposed¡¡flight¡¡includes¡¡every¡¡city¡¡except¡¡Los¡¡Angeles¡£¡¡If¡¡a¡¡travel¡¡agent¡¡were¡¡to¡¡propose¡¡¡¡

such¡¡a¡¡flight¡¡route¡¡to¡¡you£»¡¡you¡¡would¡¡probably¡¡have¡¡a¡¡panic¡¡attack¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡algorithm¡¡did¡¡not¡¡fail£»¡¡rather£»¡¡the¡¡CanContinueSearch£¨£©¡¡function¡¡did¡¡not¡¡include¡¡func

tionality¡¡to¡¡optimize¡¡the¡¡flight¡£¡¡Right¡¡now£»¡¡the¡¡algorithm¡¡says¡¡to¡¡perform¡¡a¡¡depth¡­first¡¡search£»¡¡¡¡

meaning¡¡to¡¡go¡¡down¡¡the¡¡tree¡¡before¡¡backtracking¡£¡¡So¡¡let¡¯s¡¡go¡¡through¡¡the¡¡structure¡¡in¡¡the¡¡Node¡¡¡¡

shared¡¡constructor¡¡again¡£¡¡

¡¡¡¡¡¡¡¡¡¡We¡¡started¡¡our¡¡route¡¡in¡¡Montreal£»¡¡which¡¡had¡¡the¡¡following¡¡¡¡Connections¡¡definitions£º¡¡



montreal¡£Connections¡¡=¡¡New¡¡Node£¨£©¡¡£û¡¡newyork£»¡¡toronto£»¡¡losangeles¡¡£ý¡¡



¡¡¡¡¡¡¡¡¡¡Applying¡¡our¡¡depth¡­first¡¡algorithm£»¡¡it¡¡means¡¡the¡¡first¡¡array¡¡element¡¡of¡¡the¡¡tree¡¡is¡¡consid

ered¡¡a¡¡connection£»¡¡and¡¡thus¡¡our¡¡route¡¡takes¡¡us¡¡to¡¡New¡¡York¡£¡¡New¡¡York¡¡has¡¡the¡¡following¡¡flight¡¡¡¡

connections£º¡¡



newyork¡£Connections¡¡=¡¡New¡¡Node£¨£©¡¡£û¡¡montreal£»¡¡houston£»¡¡miami¡¡£ý¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡first¡¡connection¡¡from¡¡New¡¡York¡¡is¡¡Montreal£»¡¡which¡¡is¡¡already¡¡in¡¡the¡¡flight¡¡route¡£¡¡Thus£»¡¡¡¡

the¡¡second¡¡array¡¡element¡¡is¡¡searched£»¡¡which¡¡is¡¡Houston¡£¡¡Houston¡¡has¡¡the¡¡following¡¡flight¡¡¡¡

connections£º¡¡



houston¡£Connections¡¡=¡¡New¡¡Node£¨£©¡¡£û¡¡miami£»¡¡seattle£»¡¡newyork¡¡£ý¡¡



¡¡¡¡¡¡¡¡¡¡Following¡¡the¡¡flight¡¡route¡¡from¡¡Houston£»¡¡we¡¡travel¡¡to¡¡Miami£»¡¡which¡¡has¡¡the¡¡following¡¡¡¡

connections£º¡¡



miami¡£Connections¡¡=¡¡New¡¡Node£¨£©¡¡£û¡¡toronto£»¡¡houston£»¡¡newyork¡¡£ý¡¡



¡¡¡¡¡¡¡¡¡¡Following¡¡the¡¡flight¡¡route¡¡from¡¡Miami£»¡¡we¡¡travel¡¡to¡¡Toronto£»¡¡which¡¡has¡¡the¡¡following¡¡¡¡

connections£º¡¡



toronto¡£Connections¡¡=¡¡New¡¡Node£¨£©¡¡£û¡¡miami£»¡¡seattle£»¡¡montreal¡¡£ý¡¡



¡¡¡¡¡¡¡¡¡¡At¡¡Toronto£»¡¡the¡¡first¡¡connection¡¡is¡¡Miami£»¡¡where¡¡we¡¡have¡¡already¡¡been¡£¡¡The¡¡second¡¡¡¡

connection¡¡is¡¡Seattle£»¡¡and¡¡that¡¡is¡¡our¡¡end¡¡destination¡£¡¡

¡¡¡¡¡¡¡¡¡¡So¡¡from¡¡the¡¡perspective¡¡of¡¡the¡¡algorithm£»¡¡everything¡¡worked¡£¡¡From¡¡the¡¡perspective¡¡of¡¡the¡¡¡¡

traveler£»¡¡it¡¯s¡¡not¡¡ideal¡£¡¡This¡¡demonstrates¡¡yet¡¡again¡¡how¡¡important¡¡it¡¡is¡¡to¡¡write¡¡test¡¡routines£»¡¡as¡¡¡¡

algorithms¡¡might¡¡be¡¡correct£»¡¡but¡¡they¡¡will¡¡generate¡¡responses¡¡that¡¡you¡¡might¡¡not¡¡have¡¡antici

pated¡£¡¡Improving¡¡the¡¡example¡¡is¡¡one¡¡of¡¡the¡¡exercises¡¡at¡¡the¡¡end¡¡of¡¡the¡¡chapter¡£¡¡



The¡¡Important¡¡Stuff¡¡to¡¡Remember¡¡



In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡about¡¡data¡¡structures¡¡and¡¡algorithms¡£¡¡Here¡¡are¡¡the¡¡key¡¡points¡¡to¡¡¡¡

keep¡¡in¡¡mind£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡developing¡¡a¡¡program£»¡¡you¡¡need¡¡to¡¡think¡¡of¡¡the¡¡data¡¡structures¡¡and¡¡algorithms¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡are¡¡involved¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡single¡¡best¡¡data¡¡structure¡¡and¡¡a¡¡single¡¡best¡¡algorithm¡¡do¡¡not¡¡exist¡£¡¡Every¡¡data¡¡structure¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡algorithm¡¡has¡¡promises¡£¡¡You¡¡need¡¡to¡¡choose¡¡the¡¡data¡¡structure¡¡and¡¡algorithm¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡best¡¡suits¡¡your¡¡needs¡¡with¡¡the¡¡least¡¡number¡¡of¡¡critical¡¡promises¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡134¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

112¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡D¡¡AT¡¡A¡¡¡¡S¡¡TR¡¡U¡¡CT¡¡U¡¡R¡¡E¡¡S£»¡¡¡¡¡¡DE¡¡CI¡¡SI¡¡ON¡¡S£»¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡L¡¡O¡¡OP¡¡S¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Data¡¡structures¡¡and¡¡algorithms¡¡do¡¡not¡¡need¡¡to¡¡be¡¡the¡¡same¡¡class¡£¡¡They¡¡can¡¡be¡¡different¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡types¡¡and¡¡often¡¡are¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Data¡¡structures¡¡can¡¡be¡¡implemented¡¡using¡¡value¡¡£¨Structure£©¡¡or¡¡reference¡¡£¨Class£©¡¡types¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Value¡¡types¡¡when¡¡used¡¡as¡¡data¡¡structures¡¡have¡¡three¡¡constraints¡¡that¡¡you¡¡need¡¡to¡¡be¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡aware¡¡of¡¡that¡¡relate¡¡to¡¡the¡¡fact¡¡that¡¡data¡¡is¡¡copied£»¡¡what¡¡happens¡¡when¡¡you¡¡embed¡¡refer

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ence¡¡types¡¡in¡¡value¡¡types£»¡¡and¡¡what¡¡happens¡¡when¡¡you¡¡use¡¡value¡¡types¡¡as¡¡parameters¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡methods¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡For¡¡the¡¡most¡¡part£»¡¡you¡¡will¡¡use¡¡reference¡¡types£»¡¡but¡¡you¡¡can¡¡also¡¡use¡¡value¡¡types¡£¡¡When¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡using¡¡value¡¡types£»¡¡you¡¡need¡¡to¡¡be¡¡aware¡¡of¡¡how¡¡a¡¡value¡¡behaves£»¡¡otherwise£»¡¡you¡¡might¡¡get¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡undesirable¡¡interactions¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡constructor¡¡is¡¡a¡¡special¡¡type¡¡of¡¡method¡¡that¡¡is¡¡called¡¡when¡¡a¡¡type¡¡is¡¡being¡¡instantiated¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡would¡¡assign¡¡parameters¡¡to¡¡a¡¡constructor¡¡when¡¡you¡¡want¡¡to¡¡enforce¡¡a¡¡verifiably¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡correct¡¡state¡¡for¡¡the¡¡object¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡rule¡¡of¡¡thumb¡¡when¡¡trying¡¡to¡¡decide¡¡whether¡¡to¡¡use¡¡value¡¡and¡¡reference¡¡types¡¡is¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡consider¡¡the¡¡context¡£¡¡Are¡¡you¡¡creating¡¡a¡¡simple¡¡assign¡­once¡¡structure£»¡¡or¡¡are¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡creating¡¡a¡¡plex¡¡navigable¡¡structure£¿¡¡If¡¡your¡¡structure¡¡is¡¡plex£»¡¡then¡¡use¡¡a¡¡refer

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ence¡¡type£»¡¡otherwise£»¡¡a¡¡value¡¡type¡¡is¡¡fine¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡you¡¡instantiate¡¡a¡¡type£»¡¡each¡¡object¡¡has¡¡its¡¡own¡¡set¡¡of¡¡instances¡¡of¡¡methods¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡data¡¡members¡£¡¡When¡¡a¡¡type¡¡has¡¡methods¡¡or¡¡data¡¡members¡¡declared¡¡with¡¡the¡¡Shared¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡keyword£»¡¡that¡¡type¡¡has¡¡a¡¡single¡¡instance¡¡of¡¡the¡¡shared¡¡method¡¡or¡¡data¡¡member¡¡and¡¡is¡¡not¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡associated¡¡with¡¡a¡¡type¡¡instance¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Writing¡¡the¡¡test¡¡before¡¡the¡¡type¡¡implementation¡¡allows¡¡a¡¡developer¡¡to¡¡get¡¡a¡¡feeling¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡how¡¡the¡¡type¡¡should¡¡look¡¡and¡¡behave£»¡¡and¡¡gives¡¡some¡¡guidance¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡you¡¡write¡¡methods£»¡¡you¡¡don¡¯t¡¡want¡¡to¡¡rely¡¡too¡¡heavily¡¡on¡¡magic¡¡data¡¡making¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡everything¡¡work¡£¡¡When¡¡writing¡¡classes£»¡¡you¡¡need¡¡to¡¡think¡¡in¡¡terms¡¡of¡¡IKEA¡¡furniture¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨assembly¡¡required£©£»¡¡as¡¡that¡¡will¡¡make¡¡your¡¡code¡¡more¡¡flexible¡¡and¡¡a¡¡candidate¡¡for¡¡reuse¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡you¡¡write¡¡a¡¡For¡¡loop£»¡¡think¡¡of¡¡the¡¡statements¡¡in¡¡the¡¡brackets¡¡as¡¡being¡¡code¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡generates¡¡an¡¡index¡¡that¡¡is¡¡used¡¡to¡¡retrieve¡¡the¡¡actual¡¡information¡¡being¡¡iterated¡¡over¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Decisions¡¡are¡¡implemented¡¡using¡¡a¡¡bination¡¡of¡¡If£»¡¡ElseIf£»¡¡and¡¡Else¡¡statements¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Some¡¡Things¡¡for¡¡You¡¡to¡¡Do¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡are¡¡some¡¡exercises¡¡to¡¡practice¡¡what¡¡you¡¡learned¡¡in¡¡this¡¡chapter¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡Node¡¡was¡¡declared¡¡to¡¡be¡¡a¡¡reference¡¡type¡£¡¡Can¡¡you¡¡think¡¡of¡¡where¡¡in¡¡the¡¡declaration¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡Node¡¡it¡¡would¡¡be¡¡more¡¡appropriate¡¡to¡¡use¡¡a¡¡value¡¡type£¿¡¡And¡¡if¡¡you¡¡can¡¡think¡¡of¡¡it£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡rewrite¡¡Node¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡The¡¡shared¡¡data¡¡member¡¡Node¡£RootNodes¡¡is¡¡exposed¡¡for¡¡every¡¡class¡¡to¡¡consume¡£¡¡Is¡¡there¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡way¡¡to¡¡decouple¡¡RootNodes¡¡so¡¡that¡¡the¡¡user¡¡of¡¡Node¡¡is¡¡not¡¡aware¡¡of¡¡the¡¡location¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡tree£¿¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡135¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡4¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡D¡¡AT¡¡A¡¡¡¡S¡¡TR¡¡U¡¡CT¡¡U¡¡R¡¡E¡¡S£»¡¡¡¡¡¡DE¡¡CI¡¡SI¡¡ON¡¡S£»¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡L¡¡O¡¡OP¡¡S¡¡113¡¡



3¡£¡¡¡¡We¡¡discussed¡¡a¡¡keyhole¡¡problem¡¡regarding¡¡the¡¡allocation¡¡of¡¡an¡¡array¡£¡¡Yet¡¡there¡¡is¡¡also¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡coupling¡¡problem¡¡between¡¡Node¡¡and¡¡DepthFirstSearch¡£¡¡Explain¡¡why¡¡there¡¡is¡¡a¡¡coupling¡¡¡¡

¡¡¡¡¡¡¡¡problem¡¡and¡¡outline¡¡an¡¡alternative¡¡algorithm¡¡that¡¡does¡¡not¡¡have¡¡the¡¡coupling¡¡problem¡£¡¡



4¡£¡¡¡¡Fix¡¡the¡¡CanContinueSearch£¨£©¡¡function¡¡so¡¡that¡¡an¡¡optimal¡¡flight¡¡path¡¡is¡¡found¡¡for¡¡any¡¡two¡¡¡¡

¡¡¡¡¡¡¡¡cities¡£¡¡Note¡¡that¡¡you¡¡should¡¡extend¡¡your¡¡test¡¡cases¡¡to¡¡test¡¡various¡¡scenarios¡£¡¡



5¡£¡¡¡¡Implement¡¡the¡¡breadth¡­first¡¡search¡¡algorithm¡£¡¡The¡¡breadth¡­first¡¡algorithm¡¡will¡¡search¡¡¡¡

¡¡¡¡¡¡¡¡each¡¡connection¡¡before¡¡going¡¡down¡¡further¡¡in¡¡the¡¡tree¡£¡¡Hint£º¡¡modify¡¡the¡¡behavior¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡FindNextLeg£¨£©¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡136¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡137¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

C¡¡¡¡H¡¡¡¡A¡¡¡¡P¡¡¡¡T¡¡¡¡E¡¡¡¡R¡¡¡¡¡¡¡¡¡¡5¡¡



¡¡¡ö¡¡¡ö¡¡¡ö¡¡



Learning¡¡About¡¡Visual¡¡Basic¡¡¡¡

¡¡Exception¡¡Handling¡¡



Source¡¡code¡¡can¡¡have¡¡thousands£»¡¡hundreds¡¡of¡¡thousands£»¡¡or¡¡millions¡¡of¡¡lines¡¡of¡¡source¡¡code£»¡¡¡¡

and¡¡no¡¡single¡¡human¡¡could¡¡keep¡¡track¡¡of¡¡it¡¡all¡£¡¡To¡¡keep¡¡track¡¡of¡¡all¡¡the¡¡source¡¡code£»¡¡you¡¡need¡¡a¡¡¡¡

team¡¡of¡¡developers£»¡¡and¡¡that¡¡means¡¡code¡¡written¡¡by¡¡one¡¡developer¡¡is¡¡going¡¡to¡¡be¡¡used¡¡and¡¡¡¡

modified¡¡by¡¡another¡¡developer¡£¡¡Since¡¡the¡¡two¡¡developers¡¡can¡¯t¡¡perform¡¡a¡¡Vulcan¡¡mind¡¡meld£»¡¡¡¡

they¡¡must¡¡have¡¡a¡¡well¡­understood¡¡and¡¡useful¡¡form¡¡of¡¡munication¡£¡¡But¡¡that¡¯s¡¡just¡¡part¡¡of¡¡¡¡

the¡¡solution¡£¡¡The¡¡code¡¡itself¡¡must¡¡be¡¡easy¡¡to¡¡understand¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡challenge¡¡of¡¡writing¡¡software¡¡is¡¡not¡¡creating¡¡a¡¡perfect¡¡piece¡¡of¡¡code£»¡¡but¡¡writing¡¡code¡¡¡¡

that¡¡can¡¡be¡¡understood¡¡by¡¡other¡¡developers¡¡and¡¡used¡¡by¡¡other¡¡pieces¡¡of¡¡software¡£¡¡The¡¡goal¡¡isn¡¯t¡¡¡¡

to¡¡be¡¡clever¡¡and¡¡write¡¡software¡¡that¡¡can¡¡do¡¡everything£»¡¡but¡¡to¡¡write¡¡simple£»¡¡robust£»¡¡and¡¡easy¡­to

understand¡¡software¡£¡¡The¡¡¡°keep¡¡it¡¡simple¡±¡¡approach¡¡is¡¡the¡¡best¡¡way¡¡forward¡£¡¡

¡¡¡¡¡¡¡¡¡¡Having¡¡understandable¡¡code¡¡is¡¡particularly¡¡important¡¡when¡¡things¡¡go¡¡wrong¡£¡¡Your¡¡code¡¡¡¡

should¡¡generate¡¡the¡¡appropriate¡¡errors¡£¡¡For¡¡example£»¡¡suppose¡¡your¡¡code¡¡relies¡¡on¡¡a¡¡file¡¡being¡¡¡¡

present¡£¡¡When¡¡the¡¡file¡¡is¡¡not¡¡present£»¡¡your¡¡code¡¡should¡¡generate¡¡a¡¡clear¡¡and¡¡distinct¡¡error£»¡¡such¡¡¡¡

as¡¡¡°File¡¡XYZ¡¡is¡¡not¡¡present¡¡and¡¡thus¡¡I¡¡cannot¡¡continue¡£¡±¡¡Upon¡¡seeing¡¡such¡¡an¡¡error¡¡message£»¡¡¡¡

another¡¡developer¡¡would¡¡know¡¡that¡¡he¡¡should¡¡check¡¡whether¡¡the¡¡file¡¡is¡¡actually¡¡there¡£¡¡

¡¡¡¡¡¡¡¡¡¡This¡¡chapter¡¡explains¡¡exceptions£»¡¡as¡¡errors¡¡in¡¡an¡¡application¡¡are¡¡technically¡¡known£»¡¡and¡¡how¡¡¡¡

to¡¡handle¡¡them¡£¡¡We¡¯ll¡¡begin¡¡with¡¡an¡¡overview¡¡of¡¡how¡¡exceptions¡¡fit¡¡into¡¡the¡¡structure¡¡of¡¡a¡¡program¡£¡¡¡¡



Understanding¡¡Errors£»¡¡Exceptions£»¡¡and¡¡¡¡

Exception¡¡Handling¡¡



An¡¡error¡¡is¡¡when¡¡something¡¡is¡¡not¡¡right¡¡and¡¡could¡¡be¡¡the¡¡result¡¡of¡¡incorrect¡¡data¡¡or¡¡an¡¡incorrect¡¡¡¡

calculation¡£¡¡However£»¡¡the¡¡¡¡CLR¡¡does¡¡not¡¡understand¡¡errors£»¡¡it¡¡understands¡¡only¡¡exceptions¡£¡¡

¡¡¡¡¡¡¡¡¡¡For¡¡example£»¡¡if¡¡an¡¡error¡¡is¡¡caused¡¡by¡¡multiplying¡¡two¡¡numbers¡¡rather¡¡than¡¡adding¡¡them£»¡¡¡¡

your¡¡program¡¡will¡¡continue¡¡to¡¡function£»¡¡but¡¡will¡¡produce¡¡the¡¡wrong¡¡results¡£¡¡A¡¡similar¡¡error¡¡occurs¡¡¡¡

when¡¡a¡¡user¡¡enters¡¡the¡¡wrong¡¡data¡ªthe¡¡answer¡¡will¡¡be¡¡wrong£»¡¡but¡¡the¡¡program¡¡will¡¡still¡¡run¡£¡¡

¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡case¡¡of¡¡a¡¡serious¡¡problem¡¡that¡¡is¡¡beyond¡¡the¡¡control¡¡of¡¡the¡¡user¡¡or¡¡that¡¡threatens¡¡to¡¡crash¡¡¡¡

your¡¡program£»¡¡the¡¡CLR¡¡steps¡¡in¡¡and¡¡treats¡¡this¡¡as¡¡an¡¡exception¡£¡¡This¡¡interrupts¡¡the¡¡program¡¡and¡¡¡¡

allows¡¡your¡¡code¡¡to¡¡deal¡¡with¡¡the¡¡problem£»¡¡rather¡¡than¡¡letting¡¡the¡¡program¡¡crash¡£¡¡£¨Some¡¡would¡¡¡¡

argue¡¡that¡¡an¡¡exception¡¡will¡¡not¡¡halt¡¡your¡¡entire¡¡program£»¡¡but¡¡a¡¡thread¡¡of¡¡your¡¡program£»¡¡while¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡115¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡138¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

116¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡5¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡V¡¡I¡¡SU¡¡A¡¡L¡¡¡¡¡¡B¡¡AS¡¡IC¡¡¡¡¡¡E¡¡X¡¡C¡¡E¡¡P¡¡TI¡¡ON¡¡¡¡¡¡H¡¡AN¡¡D¡¡L¡¡IN¡¡G¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡is¡¡technically¡¡true£»¡¡it¡¯s¡¡not¡¡an¡¡important¡¡distinction¡¡for¡¡this¡¡introduction¡¡to¡¡exceptions¡££©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡is¡¡called¡¡¡¡exception¡¡handling¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡understand¡¡how¡¡code¡¡organization¡¡affects¡¡exception¡¡handling£»¡¡think¡¡of¡¡an¡¡application¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡as¡¡a¡¡large¡¡corporation¡£¡¡A¡¡corporation¡¡has¡¡a¡¡chief¡¡executive¡¡officer¡¡£¨CEO£©£»¡¡then¡¡first¡­level¡¡managers£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡then¡¡mid¡­level¡¡managers¡£¡¡Corporations¡¡and¡¡management¡¡within¡¡corporations¡¡understand¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡to¡¡get¡¡anything¡¡done£»¡¡they¡¡must¡¡develop¡¡a¡¡game¡¡plan¡¡and¡¡then¡¡carry¡¡out¡¡the¡¡game¡¡plan¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡CEO¡¡or¡¡highest¡¡level¡¡manager¡¡will¡¡know¡¡about¡¡the¡¡overall¡¡game¡¡plan¡£¡¡The¡¡pany¡¡is¡¡orga

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡nized¡¡so¡¡that¡¡lower¡­level¡¡managers¡¡and¡¡workers¡¡can¡¡carry¡¡out¡¡discrete¡¡tasks¡¡as¡¡defined¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡game¡¡plan¡£¡¡In¡¡other¡¡words£»¡¡these¡¡organizational¡¡units¡¡carry¡¡out¡¡the¡¡implementation¡¡of¡¡the¡¡plan¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Translating¡¡this¡¡to¡¡software£»¡¡your¡¡code¡¡contains¡¡two¡¡types¡¡of¡¡methods£º¡¡methods¡¡that¡¡orga

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡nize¡¡the¡¡functionality¡¡and¡¡methods¡¡that¡¡implement¡¡the¡¡functionality¡£¡¡You¡¡create¡¡organizational¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡so¡¡that¡¡you¡¡have¡¡the¡¡ability¡¡to¡¡separate¡¡each¡¡task¡¡from¡¡the¡¡others¡£¡¡The¡¡work¡¡of¡¡one¡¡does¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡not¡¡affect¡¡the¡¡other£»¡¡and¡¡thus¡¡the¡¡code¡¡has¡¡been¡¡modularized¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡As¡¡with¡¡corporation¡¡reorganization£»¡¡management¡¡code¡¡is¡¡constantly¡¡being¡¡reorganized¡¡to¡¡fix¡¡bugs¡¡¡¡

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