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

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

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


we¡¯ll¡¡use¡¡a¡¡mand¡­line¡¡argument¡¡to¡¡get¡¡the¡¡file¡¯s¡¡name¡£¡¡For¡¡example£»¡¡to¡¡simply¡¡load¡¡a¡¡file¡¡¡¡

named¡¡lotto¡£txt¡¡into¡¡the¡¡TextProcessor¡¡program£»¡¡the¡¡mand¡¡line¡¡is¡¡as¡¡follows£º¡¡



TextProcessor¡£exe¡¡lotto¡£txt¡¡



¡¡¡¡¡¡¡¡¡¡A¡¡single¡¡mand¡­line¡¡parameter£»¡¡¡¡lotto¡£txt£»¡¡is¡¡passed¡¡as¡¡a¡¡string¡¡to¡¡TextProcessor¡£exe¡£¡¡¡¡

mand¡­line¡¡arguments¡¡are¡¡separated¡¡from¡¡each¡¡other¡¡using¡¡spaces¡£¡¡In¡¡the¡¡context¡¡of¡¡Windows£»¡¡¡¡

this¡¡is¡¡a¡¡problem£»¡¡because¡¡paths¡¡can¡¡contain¡¡spaces¡£¡¡For¡¡example£»¡¡the¡¡following¡¡mand¡¡line¡¡¡¡

would¡¡be¡¡passed¡¡as¡¡two¡¡mand¡­line¡¡arguments¡£¡¡



TextProcessor¡£exe¡¡c£ºMy¡¡Documentsuserlotto¡£txt¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡space¡¡between¡¡My¡¡and¡¡Documents¡¡tells¡¡the¡¡console¡¡that¡¡there¡¡are¡¡two¡¡arguments¡£¡¡To¡¡fix¡¡¡¡

that¡¡problem£»¡¡you¡¡need¡¡to¡¡enclose¡¡the¡¡path¡¡in¡¡quotation¡¡marks£º¡¡



TextProcessor¡£exe¡¡¡¨c£ºMy¡¡Documentsuserlotto¡£txt¡¨¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡mand¡¡line¡¡may¡¡also¡¡include¡¡additional¡¡parameters£»¡¡as¡¡in¡¡this¡¡example£º¡¡



TextProcessor¡£exe¡¡¡­count¡¡10¡¡lotto¡£txt¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡parameter¡¡¡¡¡­count¡¡expects¡¡a¡¡value£»¡¡which¡¡is¡¡¡¡10¡¡in¡¡this¡¡example¡£¡¡Traditionally£»¡¡options¡¡¡¡

are¡¡specified¡¡using¡¡key/value¡¡pairs£»¡¡because¡¡console¡¡applications¡¡allow¡¡the¡¡options¡¡to¡¡be¡¡placed¡¡¡¡

in¡¡any¡¡order¡£¡¡The¡¡exception¡¡is¡¡the¡¡last¡¡argument£»¡¡which¡¡is¡¡usually¡¡the¡¡data¡¡on¡¡which¡¡to¡¡operate¡£¡¡



¡öNote¡¡¡¡For¡¡more¡¡information¡¡about¡¡the¡¡permutations¡¡and¡¡binations¡¡of¡¡mand¡¡lines£»¡¡and¡¡what¡¡a¡¡¡¡

console¡¡can¡¡do£»¡¡see¡¡http£º//en¡£wikipedia¡£org/wiki/mand_line_interface¡£¡¡



Piping¡¡Data¡¡



Another¡¡solution¡¡is¡¡to¡¡use¡¡a¡¡mand¡¡that¡¡reads¡¡the¡¡file¡¡and¡¡pipes¡¡the¡¡contents¡¡of¡¡the¡¡file¡¡to¡¡¡¡

a¡¡stream¡£¡¡The¡¡console¡¡application¡¡reads¡¡the¡¡stream¡¡and¡¡processes¡¡the¡¡data¡£¡¡The¡¡following¡¡is¡¡¡¡

an¡¡example¡¡of¡¡a¡¡mand¡¡line¡¡that¡¡pipes¡¡data¡£¡¡The¡¡pipe¡¡operation¡¡is¡¡indicated¡¡by¡¡the¡¡pipe¡¡¡¡

character¡¡£¨¡¡£ü£©¡£¡¡



type¡¡lotto¡£txt¡¡£ü¡¡TextProcessor¡£exe¡¡



¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡the¡¡mand¡¡type£»¡¡which¡¡ordinarily¡¡reads¡¡a¡¡file¡¡and¡¡displays¡¡it¡¡on¡¡the¡¡¡¡

console£»¡¡reads¡¡in¡¡the¡¡lotto¡£txt¡¡file¡¡and¡¡pipes¡¡it¡¡to¡¡the¡¡console¡£¡¡Then¡¡TextProcessor¡£exe¡¡reads¡¡¡¡

from¡¡the¡¡console£»¡¡processes¡¡the¡¡data£»¡¡and¡¡pipes¡¡it¡¡back¡¡to¡¡the¡¡console¡£¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡274¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

252¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡0¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡P¡¡E¡¡R¡¡S¡¡IS¡¡TE¡¡N¡¡CE¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡the¡¡scope¡¡of¡¡the¡¡TextProcessor¡¡application£»¡¡the¡¡mand¡¡lines¡¡listed¡¡in¡¡Table¡¡10¡­1¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡valid¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Table¡¡10¡­1¡£¡¡¡¡TextProcessor¡¡mand¡¡Lines¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mand¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Description¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextProcessor¡£exe¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Without¡¡any¡¡arguments£»¡¡the¡¡data¡¡will¡¡be¡¡read¡¡from¡¡the¡¡console¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pipe¡¡and¡¡written¡¡back¡¡to¡¡the¡¡console¡¡pipe¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextProcessor¡£exe¡¡£§filename£§¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡one¡¡argument£»¡¡the¡¡data¡¡will¡¡be¡¡read¡¡from¡¡the¡¡specified¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡file¡¡and¡¡written¡¡to¡¡the¡¡console¡¡pipe¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextProcessor¡£exe¡¡¡­out¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡the¡¡¡¡¡­out¡¡parameter¡¡with¡¡two¡¡arguments£»¡¡the¡¡first¡¡file¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£§filename£§¡¡£§filename£§¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡specified¡¡is¡¡where¡¡the¡¡data¡¡will¡¡be¡¡written£»¡¡and¡¡the¡¡last¡¡file¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡specified¡¡is¡¡the¡¡file¡¡to¡¡read¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextProcessor¡£exe¡¡¡­out¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡the¡¡¡¡¡­out¡¡parameter¡¡with¡¡one¡¡argument£»¡¡the¡¡data¡¡is¡¡read¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£§filename£§¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡from¡¡the¡¡console¡¡pipe¡¡and¡¡written¡¡to¡¡a¡¡file¡£¡¡Notice¡¡that¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡output¡¡file¡¡name¡¡is¡¡explicitly¡¡defined£»¡¡otherwise£»¡¡if¡¡a¡¡single¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡identifier¡¡is¡¡given£»¡¡the¡¡console¡¡application¡¡would¡¡not¡¡know¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡whether¡¡you¡¡are¡¡reading¡¡or¡¡writing¡¡to¡¡a¡¡file¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextProcessor¡£exe¡¡¡­help¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Outputs¡¡to¡¡the¡¡console¡¡how¡¡to¡¡use¡¡TextProcessor¡£¡¡The¡¡help¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡also¡¡generated¡¡when¡¡the¡¡parameters¡¡are¡¡specified¡¡incorrectly¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Building¡¡a¡¡Shell¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementing¡¡TextProcessor¡¡from¡¡an¡¡architectural¡¡perspective¡¡involves¡¡writing¡¡two¡¡pieces¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code£º¡¡a¡¡module¡¡to¡¡read/write¡¡to¡¡a¡¡stream¡¡and¡¡a¡¡module¡¡to¡¡process¡¡the¡¡stream¡£¡¡By¡¡separating¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡two¡¡modules£»¡¡the¡¡processor¡¡is¡¡not¡¡dependent¡¡on¡¡where¡¡the¡¡data¡¡originated¡£¡¡This¡¡also¡¡allows¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡developer¡¡to¡¡define¡¡an¡¡interface¡¡that¡¡is¡¡implemented¡¡to¡¡process¡¡the¡¡data¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Assembling¡¡the¡¡Pieces¡¡Using¡¡an¡¡Echo¡¡Program¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡lottery¡­prediction¡¡program¡¡is¡¡a¡¡case¡¡where¡¡I¡¡know¡¡something¡¡about¡¡the¡¡topic£»¡¡but¡¡not¡¡all¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡details¡£¡¡Developing¡¡code¡¡is¡¡a¡¡constant¡¡challenge¡¡of¡¡figuring¡¡out¡¡which¡¡APIs¡¡to¡¡use¡£¡¡In¡¡this¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡of¡¡situation£»¡¡so¡¡that¡¡I¡¡don¡¯t¡¡get¡¡bogged¡¡down¡¡in¡¡API¡¡hunting£»¡¡I¡¡first¡¡assemble¡¡all¡¡of¡¡the¡¡pieces¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡I¡¡need¡¡for¡¡the¡¡application¡£¡¡I¡¡develop¡¡what¡¡I¡¡call¡¡an¡¡echo¡¡program¡£¡¡An¡¡echo¡¡program¡¡has¡¡all¡¡of¡¡its¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pieces¡¡in¡¡place£»¡¡and¡¡when¡¡called¡¡will¡¡seem¡¡like¡¡it¡¡functions¡£¡¡The¡¡echo¡¡part¡¡es¡¡in¡¡when¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡end¡¡piece¡¡of¡¡functionality¡¡is¡¡called¡¡and¡¡it¡¡returns¡¡the¡¡data¡¡that¡¡was¡¡sent¡¡to¡¡it¡£¡¡In¡¡essence£»¡¡the¡¡end¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡piece¡¡is¡¡acting¡¡like¡¡an¡¡echo¡£¡¡The¡¡cleverness¡¡behind¡¡the¡¡echo¡¡is¡¡that¡¡it¡¡requires¡¡no¡¡implementa

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tion£»¡¡yet¡¡it¡¡demonstrates¡¡the¡¡plete¡¡flow¡¡of¡¡data¡¡and¡¡whether¡¡that¡¡data¡¡flow¡¡is¡¡workable¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡echo¡¡program¡¡is¡¡not¡¡a¡¡final¡¡program¡£¡¡The¡¡echo¡¡program¡¡is¡¡a¡¡temporary¡¡solution¡¡for¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡intermediate¡¡goal¡£¡¡When¡¡building¡¡an¡¡application¡¡with¡¡intermediate¡¡goals£»¡¡you¡¡are¡¡using¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡iterative¡¡development¡¡technique¡£¡¡The¡¡iterations¡¡are¡¡not¡¡visible¡¡to¡¡your¡¡other¡¡team¡¡members¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡are¡¡pletely¡¡private¡£¡¡However£»¡¡the¡¡iterations¡¡will¡¡keep¡¡you¡¡focused¡¡on¡¡solving¡¡a¡¡problem£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡rather¡¡than¡¡trying¡¡to¡¡implement¡¡a¡¡large¡¡piece¡¡of¡¡code¡¡that¡¡you¡¡will¡¡not¡¡be¡¡able¡¡to¡¡fully¡¡test¡¡for¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡while¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Test¡­driven¡¡development£»¡¡for¡¡the¡¡most¡¡part£»¡¡is¡¡a¡¡bottom¡­up¡¡development¡¡approach¡£¡¡You¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡develop¡¡a¡¡core¡¡piece¡¡of¡¡functionality£»¡¡test¡¡it£»¡¡and¡¡then¡¡write¡¡code¡¡that¡¡uses¡¡the¡¡tested¡¡piece¡¡of¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡275¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡A¡¡PT¡¡E¡¡R¡¡¡¡¡¡1¡¡0¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡O¡¡U¡¡T¡¡¡¡P¡¡E¡¡R¡¡S¡¡IS¡¡T¡¡E¡¡N¡¡CE¡¡253¡¡



functionality¡£¡¡But¡¡sometimes¡¡you¡¡need¡¡to¡¡develop¡¡in¡¡a¡¡top¡­down¡¡fashion¡£¡¡I¡¡typically¡¡develop¡¡¡¡

code¡¡top¡­down¡¡when¡¡I¡¡am¡¡trying¡¡to¡¡nail¡¡down¡¡an¡¡overall¡¡architecture¡£¡¡The¡¡problem¡¡with¡¡devel

oping¡¡top¡­down¡¡is¡¡that¡¡you¡¡don¡¯t¡¡yet¡¡have¡¡the¡¡bottom¡¡code¡£¡¡In¡¡other¡¡words£»¡¡you¡¡are¡¡writing¡¡¡¡

code¡¡with¡¡no¡¡working¡¡code¡£¡¡So¡¡that¡¡your¡¡code¡¡does¡¡have¡¡some¡¡meaning£»¡¡you¡¡develop¡¡an¡¡echo¡£¡¡¡¡

The¡¡echo¡¡solves¡¡the¡¡problem¡¡of¡¡working¡¡code¡¡and¡¡allows¡¡you¡¡to¡¡focus¡¡on¡¡getting¡¡the¡¡individual¡¡¡¡

pieces¡¡to¡¡fit¡¡together¡£¡¡Once¡¡the¡¡pieces¡¡are¡¡working£»¡¡and¡¡the¡¡echo¡¡was¡¡successful£»¡¡you¡¡can¡¡start¡¡¡¡

filling¡¡in¡¡the¡¡implementations¡£¡¡Some¡¡developers¡¡call¡¡the¡¡echo¡¡a¡¡¡¡mock¡¡implementation¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡Here£»¡¡I¡¯ll¡¡explain¡¡developing¡¡the¡¡sample¡¡application¡¡by¡¡assembling¡¡individual¡¡pieces¡¡in¡¡a¡¡¡¡

top¡­down¡¡manner£»¡¡focusing¡¡on¡¡getting¡¡a¡¡single¡¡echo¡¡implemented¡£¡¡Then¡¡once¡¡the¡¡overall¡¡flow¡¡¡¡

is¡¡plete£»¡¡the¡¡individual¡¡pieces¡¡will¡¡be¡¡implemented¡¡pletely¡£¡¡Figure¡¡10¡­2¡¡illustrates¡¡¡¡

a¡¡plete¡¡architecture¡¡for¡¡the¡¡lottery¡­prediction¡¡program£»¡¡including¡¡the¡¡pipeline¡¡for¡¡the¡¡¡¡

TextProcessor¡¡console¡¡application¡£¡¡



Figure¡¡10¡­2¡£¡¡Architecture¡¡of¡¡a¡¡reader/writer¡¡application¡¡using¡¡a¡¡general¡¡assembly¡¡



Reading¡¡and¡¡Writing¡¡to¡¡a¡¡Stream¡¡



For¡¡developing¡¡the¡¡lottery¡­prediction¡¡application£»¡¡we¡¯ll¡¡use¡¡a¡¡piece¡¡of¡¡bootstrap¡¡code¡¡to¡¡initiate¡¡¡¡

the¡¡reading¡¡and¡¡writing¡¡library£»¡¡which¡¡then¡¡calls¡¡the¡¡specific¡¡implementation¡£¡¡Bootstrap¡¡code¡¡is¡¡¡¡

code¡¡that¡¡does¡¡not¡¡actually¡¡perform¡¡the¡¡processing£»¡¡but¡¡is¡¡responsible¡¡for¡¡setting¡¡up¡¡and¡¡initi

ating¡¡another¡¡piece¡¡of¡¡source¡¡code¡¡that¡¡will¡¡do¡¡the¡¡processing¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡This¡¡is¡¡the¡¡same¡¡sort¡¡of¡¡architecture¡¡as¡¡we¡¡set¡¡up¡¡in¡¡Chapter¡¡8¡¯s¡¡example£»¡¡for¡¡the¡¡applica

tion¡¡to¡¡control¡¡the¡¡lights¡¡of¡¡a¡¡building¡£¡¡In¡¡that¡¡case£»¡¡the¡¡controller¡¡was¡¡a¡¡generic¡¡piece¡¡of¡¡software¡¡¡¡

that¡¡called¡¡an¡¡interface£»¡¡but¡¡did¡¡not¡¡know¡¡about¡¡the¡¡individual¡¡implementations¡£¡¡The¡¡focus¡¡¡¡

there¡¡was¡¡on¡¡developing¡¡the¡¡room¡¡implementations£»¡¡and¡¡the¡¡lighting¡¡controller¡¡was¡¡left¡¡as¡¡a¡¡¡¡

nebulous¡¡to¡­do¡¡task¡£¡¡Here£»¡¡we¡¯ll¡¡go¡¡through¡¡the¡¡creation¡¡of¡¡a¡¡plete¡¡working¡¡application£»¡¡¡¡

including¡¡the¡¡controller¡¡and¡¡implementation¡£¡¡Note¡¡this¡¡chapter¡¡is¡¡light¡¡on¡¡testing¡¡routines£»¡¡¡¡

both¡¡for¡¡brevity¡¡and¡¡because¡¡one¡¡of¡¡the¡¡exercises¡¡at¡¡the¡¡end¡¡of¡¡the¡¡chapter¡¡is¡¡for¡¡you¡¡to¡¡e¡¡up¡¡¡¡

with¡¡a¡¡testing¡¡plan¡£¡¡

¡¡¡¡¡¡¡¡¡¡We¡¡want¡¡to¡¡be¡¡able¡¡to¡¡process¡¡the¡¡following¡¡mand¡¡line¡£¡¡¡¡



type¡¡lotto¡£txt¡¡£ü¡¡TextProcessor¡£exe¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡276¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

254¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡0¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡P¡¡E¡¡R¡¡S¡¡IS¡¡TE¡¡N¡¡CE¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡TextProcessor¡£exe¡¡cannot¡¡read¡¡the¡¡data¡¡from¡¡the¡¡pipe£»¡¡an¡¡exception¡¡will¡¡be¡¡thrown¡¡at¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡console¡¡level£»¡¡indicating¡¡that¡¡the¡¡piped¡¡data¡¡was¡¡not¡¡read¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡For¡¡the¡¡application¡¡to¡¡work£»¡¡the¡¡lotto¡£txt¡¡and¡¡TextProcessor¡£exe¡¡files¡¡must¡¡be¡¡in¡¡the¡¡same¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡directory¡£¡¡By¡¡default£»¡¡TextProcessor¡£exe¡¡is¡¡in¡¡the¡¡¡¡£§Visual¡¡Studio¡¡project£§bindebug¡¡directory¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Copy¡¡TextProcessor¡£exe¡¡into¡¡the¡¡lotto¡£txt¡¡directory£»¡¡or¡¡vice¡¡versa£»¡¡or¡¡you¡¡could¡¡even¡¡copy¡¡them¡¡both¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡into¡¡another¡¡directory¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡architecture¡¡of¡¡TextProcessor£»¡¡the¡¡bootstrap¡¡code¡¡is¡¡in¡¡the¡¡ReaderWriter¡¡project¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡TextProcessor¡¡console¡¡application¡¡must¡¡call¡¡the¡¡bootstrap¡¡code¡¡and¡¡instantiate¡¡a¡¡local¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡that¡¡has¡¡implemented¡¡the¡¡IProcessor¡¡interface¡£¡¡The¡¡Main£¨£©¡¡method¡¡of¡¡TextProcessor¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implemented¡¡as¡¡follows¡¡£¨this¡¡is¡¡the¡¡best¡¡time¡¡to¡¡add¡¡a¡¡reference¡¡to¡¡the¡¡ReaderWriter¡¡project¡¡by¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡right¡­clicking¡¡TextProcessor¡¡and¡¡choosing¡¡Add¡¡Reference¡¡¡¡Projects¡¡¡¡ReaderWriter£©£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡ReaderWriter¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Module¡¡Module1¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡Main£¨ByVal¡¡args¡¡As¡¡String£¨£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Bootstrap¡£Start£¨args£»¡¡New¡¡LottoTicketProcessor£¨£©£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Module¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextProcessor¡£Main£¨£©¡¡passes¡¡all¡¡of¡¡the¡¡given¡¡arguments¡¡£¨contained¡¡in¡¡the¡¡¡¡args¡¡array£©¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡actual¡¡processing¡¡routine¡¡£¨Bootstrap¡£Start£¨£©£©¡£¡¡The¡¡¡¡LottoTicketProcessor¡¡class¡¡imple

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ments¡¡the¡¡IProcessor¡¡interface¡¡and¡¡will¡¡serve¡¡for¡¡the¡¡temporary¡¡purpose¡¡of¡¡echoing¡¡data¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡IProcessor¡¡interface¡¡is¡¡defined¡¡in¡¡the¡¡¡¡ReaderWriter¡¡project¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IProcessor¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function¡¡Process£¨ByVal¡¡input¡¡As¡¡String£©¡¡As¡¡String¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡IProcessor¡¡interface¡¡has¡¡a¡¡single¡¡method¡¡¡¡Process£¨£©£»¡¡which¡¡accepts¡¡a¡¡string¡¡to¡¡be¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡processed£»¡¡and¡¡the¡¡return¡¡value¡¡is¡¡the¡¡processed¡¡string¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡implementation¡¡of¡¡¡¡LottoLibrary¡£LottoTicketProcessor¡¡is¡¡as¡¡follows¡¡£¨remember¡¡to¡¡¡¡

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