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

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡eter¡¡buffer¡¡into¡¡a¡¡series¡¡of¡¡string¡¡tokens¡£¡¡Using¡¡safe¡¡exception¡¡coding£»¡¡if¡¡the¡¡data¡¡could¡¡not¡¡be¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡parsed£»¡¡you¡¡could¡¡throw¡¡an¡¡exception£»¡¡or¡¡you¡¡could¡¡return¡¡a¡¡Nothing¡¡value¡¡indicating¡¡that¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡buffer¡¡could¡¡not¡¡be¡¡parsed¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡caller¡¡code¡¡knows¡¡that¡¡there¡¡is¡¡the¡¡possibility¡¡of¡¡a¡¡Nothing¡¡value¡¡when¡¡calling¡¡Tokenize£¨£©£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡thus¡¡has¡¡an¡¡If¡¡test¡¡to¡¡check¡¡for¡¡the¡¡Nothing¡¡value¡£¡¡The¡¡If¡¡test¡¡is¡¡defensive¡¡coding£»¡¡but¡¡it¡¡also¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡adds¡¡plexity¡¡because¡¡you¡¡need¡¡to¡¡verify¡¡for¡¡a¡¡Nothing¡¡value¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡What¡¡if¡¡Tokenize£¨£©¡¡were¡¡a¡¡bit¡¡smarter¡¡and¡¡decided¡¡to¡¡return¡¡an¡¡empty¡¡array¡¡to¡¡indicate¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡empty¡¡result¡¡set£¿¡¡The¡¡logic¡¡of¡¡this¡¡is¡¡not¡¡incorrect£»¡¡because¡¡the¡¡caller¡¡expects¡¡either¡¡a¡¡result¡¡set¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡items¡¡or¡¡a¡¡result¡¡set¡¡with¡¡nothing¡¡in¡¡it¡£¡¡If¡¡a¡¡dramatically¡¡bad¡¡parsing¡¡error¡¡has¡¡occurred£»¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡only¡¡recourse¡¡is¡¡to¡¡throw¡¡an¡¡exception¡£¡¡Here¡¡is¡¡the¡¡rewritten¡¡code£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡DefaultStateRight¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡Function¡¡Tokenize£¨ByVal¡¡buffer¡¡As¡¡String£©¡¡¡¡As¡¡String£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡String£¨¡­1£©¡¡£û¡¡£ý¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡IterateBuffers£¨ByVal¡¡buffer¡¡As¡¡String£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡found¡¡As¡¡String£¨£©¡¡=¡¡Tokenize£¨buffer£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Found¡¡£¨¡¨¡¡&¡¡found£¨c1£©¡¡&¡¡¡¨£©¡¨£©¡¡

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

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡rewritten¡¡code£»¡¡Tokenize£¨£©¡¡returns¡¡an¡¡empty¡¡array¡¡that£»¡¡when¡¡iterated¡¡using¡¡a¡¡For¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡loop£»¡¡will¡¡cause¡¡zero¡¡iterations¡£¡¡This¡¡is¡¡exception¡­safe¡¡code¡¡with¡¡improved¡¡readability¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡But¡¡what¡¡happens¡¡if¡¡Tokenize£¨£©¡¡does¡¡throw¡¡an¡¡exception£¿¡¡With¡¡Tokenize£¨£©¡¡throwing¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡exception¡¡and¡¡the¡¡lack¡¡of¡¡a¡¡Try/Catch¡¡block¡¡in¡¡IterateBuffers£¨£©£»¡¡it¡¡looks¡¡like¡¡IterateBuffers£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡written¡¡incorrectly¡£¡¡However£»¡¡IterateBuffers£¨£©¡¡is¡¡not¡¡written¡¡incorrectly£»¡¡because¡¡Tokenize£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡throw¡¡an¡¡exception¡¡only¡¡if¡¡something¡¡really¡¡problematic¡¡has¡¡occurred¡£¡¡A¡¡big¡¡problem¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡beyond¡¡the¡¡scope¡¡of¡¡the¡¡IterateBuffers£¨£©¡¡method£»¡¡and¡¡thus¡¡needs¡¡to¡¡be¡¡handled¡¡at¡¡a¡¡higher¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡level¡£¡¡Think¡¡of¡¡it¡¡as¡¡the¡¡situation¡¡where¡¡you¡¡have¡¡a¡¡criminal¡¡case¡¡and¡¡the¡¡local¡¡municipal¡¡court¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡automatically¡¡delegates¡¡the¡¡case¡¡to¡¡the¡¡provincial¡¡or¡¡state¡¡level£»¡¡because¡¡those¡¡courts¡¡are¡¡equipped¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡deal¡¡with¡¡such¡¡a¡¡case¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡155¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡5¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡V¡¡I¡¡SU¡¡A¡¡L¡¡¡¡¡¡B¡¡AS¡¡IC¡¡¡¡¡¡E¡¡X¡¡CE¡¡PT¡¡I¡¡ON¡¡¡¡¡¡HA¡¡N¡¡D¡¡L¡¡IN¡¡G¡¡133¡¡



Processing¡¡Errors¡¡That¡¡Are¡¡Warnings¡¡



One¡¡of¡¡the¡¡silliest¡¡things¡¡that¡¡programs¡¡do¡¡is¡¡exit¡¡when¡¡they¡¡could¡¡have¡¡continued¡¡working¡£¡¡It¡¡¡¡

reminds¡¡me¡¡of¡¡when¡¡my¡¡family¡¡lived¡¡on¡¡the¡¡French¡¡Rivera£»¡¡where¡¡it¡¡does¡¡not¡¡rain¡¡too¡¡often¡£¡¡Our¡¡¡¡

two¡¡bulldogs¡¡were¡¡used¡¡to¡¡the¡¡nice¡¡weather£»¡¡and¡¡at¡¡the¡¡slightest¡¡hint¡¡of¡¡moisture¡¡in¡¡the¡¡air£»¡¡they¡¡¡¡

would¡¡refuse¡¡to¡¡go¡¡outside¡£¡¡Our¡¡male¡¡dog¡¡Big¡¡Boss¡¡£¨Man£©¡¡would¡¡stand¡¡in¡¡the¡¡doorway£»¡¡stick¡¡his¡¡¡¡

nose¡¡out¡¡slightly£»¡¡and¡¡take¡¡a¡¡few¡¡deep¡¡breaths¡£¡¡If¡¡he¡¡sensed¡¡the¡¡slightest¡¡bit¡¡of¡¡moisture£»¡¡instantly¡¡¡¡

you¡¡were¡¡dragging¡¡an¡¡80¡­pound¡¡concrete¡¡block¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡point¡¡is¡¡that£»¡¡like¡¡our¡¡bulldogs£»¡¡programs¡¡sometimes¡¡overreact¡¡to¡¡situations¡£¡¡For¡¡fear¡¡¡¡

of¡¡having¡¡problems¡¡or¡¡not¡¡doing¡¡something¡¡correctly£»¡¡they¡¡instantly¡¡shut¡¡down¡£¡¡

¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡say¡¡that¡¡you¡¡have¡¡a¡¡program¡¡that¡¡requires¡¡a¡¡configuration¡¡file¡¡to¡¡run¡£¡¡What¡¡happens¡¡¡¡

when¡¡the¡¡configuration¡¡file¡¡does¡¡not¡¡exist£¿¡¡One¡¡approach¡¡is¡¡to¡¡panic¡¡and¡¡exit¡£¡¡The¡¡panic¡¡approach¡¡¡¡

will¡¡work£»¡¡but¡¡what¡¡if¡¡multiple¡¡problems¡¡follow¡¡from¡¡the¡¡first¡¡one£¿¡¡Then¡¡you¡¡are¡¡painstakingly¡¡¡¡

hitting¡¡one¡¡error¡¡after¡¡another¡£¡¡Another¡¡approach¡¡is¡¡to¡¡use¡¡a¡¡default¡¡action¡£¡¡In¡¡this¡¡example£»¡¡the¡¡¡¡

default¡¡action¡¡could¡¡be¡¡to¡¡display¡¡a¡¡dialog¡¡box¡¡asking¡¡the¡¡user¡¡to¡¡select¡¡a¡¡configuration¡¡file£»¡¡or¡¡¡¡

the¡¡program¡¡could¡¡create¡¡a¡¡default¡¡file£»¡¡as¡¡in¡¡this¡¡example£º¡¡



Try¡¡¡¡

¡¡¡¡¡¡¡¡LoadConfiguration£¨£©¡¡

Catch¡¡ex¡¡As¡¡ConfigurationException¡¡

¡¡¡¡¡¡¡¡¡¡CreateDefaultConfiguration£¨£©¡¡

End¡¡Try¡¡



¡¡¡¡¡¡¡¡¡¡Here£»¡¡the¡¡¡¡LoadConfiguration£¨£©¡¡method¡¡is¡¡in¡¡a¡¡Try/Catch¡¡block£»¡¡but¡¡the¡¡Catch¡¡block¡¡¡¡

catches¡¡only¡¡ConfigurationException¡¡failures¡¡£¨a¡¡built¡­in¡¡Visual¡¡Basic¡¡exception£©¡£¡¡If¡¡there¡¡is¡¡a¡¡¡¡

ConfigurationException¡¡failure£»¡¡then¡¡a¡¡default¡¡configuration¡¡is¡¡created¡£¡¡With¡¡a¡¡default¡¡config

uration£»¡¡the¡¡program¡¡can¡¡continue¡¡processing¡£¡¡Using¡¡the¡¡filtering¡¡capabilities¡¡of¡¡exceptions£»¡¡if¡¡¡¡

another¡¡exception¡¡is¡¡thrown¡¡in¡¡¡¡LoadConfiguration£¨£©£»¡¡then¡¡some¡¡higher¡­level¡¡exception¡¡¡¡

handler¡¡will¡¡process¡¡it¡£¡¡

¡¡¡¡¡¡¡¡¡¡When¡¡processing¡¡an¡¡error¡¡that¡¡is¡¡a¡¡warning£»¡¡the¡¡important¡¡steps¡¡are¡¡to¡¡filter¡¡for¡¡the¡¡specific¡¡¡¡

exception¡¡and¡¡implement¡¡an¡¡appropriate¡¡exception¡¡handler¡¡that¡¡has¡¡been¡¡properly¡¡tested¡£¡¡Don¡¯t¡¡¡¡

try¡¡to¡¡implement¡¡a¡¡fix¡­all¡¡exception¡¡handler£»¡¡because¡¡you¡¡will¡¡never¡¡be¡¡able¡¡to¡¡implement¡¡a¡¡¡¡

proper¡¡handler¡¡and¡¡thus¡¡will¡¡cause¡¡more¡¡problems¡£¡¡In¡¡the¡¡handler¡¡to¡¡fix¡¡the¡¡problem£»¡¡make¡¡¡¡

sure¡¡that¡¡you¡¡don¡¯t¡¡generate¡¡an¡¡exception¡£¡¡If¡¡you¡¡do£»¡¡that¡¡exception¡¡will¡¡be¡¡sent¡¡to¡¡a¡¡higher¡¡¡¡

method¡¡caller¡£¡¡



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



In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡about¡¡errors¡¡and¡¡exceptions¡£¡¡Here¡¡are¡¡the¡¡key¡¡points¡¡to¡¡keep¡¡in¡¡mind£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Errors¡¡and¡¡exceptions¡¡will¡¡always¡¡occur¡¡in¡¡your¡¡programs¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Your¡¡code¡¡is¡¡split¡¡into¡¡a¡¡tree¡¡very¡¡much¡¡like¡¡a¡¡management¡¡hierarchy¡£¡¡The¡¡hierarchy¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡contains¡¡two¡¡types¡¡of¡¡code£º¡¡code¡¡that¡¡organizes¡¡and¡¡code¡¡that¡¡implements¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Exceptions¡¡are¡¡caught¡¡using¡¡Try/Catch¡¡blocks¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡Finally¡¡block¡¡is¡¡used¡¡to¡¡execute¡¡code£»¡¡regardless¡¡of¡¡whether¡¡an¡¡exception¡¡is¡¡thrown£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡to¡¡reset¡¡state¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡156¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Code¡¡that¡¡implements¡¡has¡¡the¡¡responsibility¡¡of¡¡throwing¡¡exceptions¡£¡¡Code¡¡that¡¡imple

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ments¡¡does¡¡not¡¡try¡¡to¡¡fix¡¡or¡¡swallow¡¡the¡¡exception¡£¡¡This¡¡means¡¡code¡¡that¡¡implements¡¡will¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implement¡¡a¡¡¡¡Finally¡¡block¡¡to¡¡reset¡¡state£»¡¡but¡¡usually¡¡not¡¡a¡¡Catch¡¡block¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Code¡¡that¡¡organizes¡¡has¡¡the¡¡responsibility¡¡of¡¡being¡¡aware¡¡that¡¡exceptions¡¡might¡¡occur¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡means¡¡code¡¡that¡¡organizes¡¡will¡¡implement¡¡Catch¡¡blocks¡¡to¡¡catch¡¡exceptions¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡process¡¡them¡£¡¡Usually£»¡¡this¡¡code¡¡will¡¡not¡¡have¡¡a¡¡¡¡Finally¡¡implementation£»¡¡but¡¡it¡¡may¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡filter¡¡exceptions¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Exceptions¡¡can¡¡be¡¡filtered¡¡to¡¡determine¡¡which¡¡exceptions¡¡will¡¡be¡¡captured¡¡and¡¡which¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cannot¡¡be¡¡captured¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡You¡¡can¡¡help¡¡make¡¡your¡¡code¡¡exception¡­safe¡¡by¡¡implementing¡¡sandboxing¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡functionality¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Implement¡¡default¡¡state¡¡so¡¡that¡¡your¡¡code¡¡is¡¡easier¡¡to¡¡read¡¡and¡¡maintain¡£¡¡



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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡apply¡¡what¡¡you¡¯ve¡¡learned¡¡in¡¡this¡¡chapter£»¡¡here¡¯s¡¡what¡¡you¡¡can¡¡do£»¡¡summed¡¡up¡¡in¡¡a¡¡single¡¡step£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡Rewrite¡¡all¡¡of¡¡the¡¡code¡¡examples¡¡in¡¡Chapter¡¡4¡¡to¡¡be¡¡exception¡­safe¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡157¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



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



Learning¡¡the¡¡Basics¡¡of¡¡Object

Oriented¡¡Programming¡¡



At¡¡this¡¡point£»¡¡you¡¡should¡¡be¡¡fortable¡¡with¡¡writing¡¡basic¡¡Visual¡¡Basic¡¡code£»¡¡but¡¡your¡¡coding¡¡¡¡

style¡¡would¡¡solve¡¡problems¡¡directly¡¡without¡¡considering¡¡reusability¡¡or¡¡other¡¡more¡¡advanced¡¡¡¡

concepts¡£¡¡You¡¡could¡¡code¡¡yourself¡¡out¡¡of¡¡a¡¡wet¡¡paper¡¡bag£»¡¡but¡¡once¡¡you¡¡were¡¡out¡¡of¡¡the¡¡bag£»¡¡you¡¡¡¡

would¡¡have¡¡no¡¡idea¡¡what¡¡to¡¡do¡¡next¡£¡¡£¨In¡¡case¡¡you¡¯re¡¡interested£»¡¡the¡¡phrase£»¡¡¡°You¡¡couldn¡¯t¡¡do¡¡£§fill¡¡¡¡

in¡¡topic£§¡¡out¡¡of¡¡a¡¡wet¡¡paper¡¡bag¡±¡¡implies¡¡that¡¡your¡¡skills¡¡in¡¡a¡¡certain¡¡area¡¡are¡¡so¡¡weak¡¡that¡¡a¡¡wet¡¡¡¡

paper¡¡bag¡¡is¡¡more¡¡overpowering¡£¡¡The¡¡reference¡¡to¡¡wet¡¡paper¡¡bag¡¡es¡¡from¡¡the¡¡fact¡¡that¡¡wet¡¡¡¡

paper¡¡bags¡¡have¡¡no¡¡holding¡¡power¡¡and¡¡will¡¡tear¡¡at¡¡the¡¡slightest¡¡nudging¡££©¡¡

¡¡¡¡¡¡¡¡¡¡This¡¡chapter¡¡focuses¡¡on¡¡reusing¡¡base¡¡functionality£»¡¡where¡¡two¡¡classes¡¡share¡¡methods¡¡and¡¡¡¡

properties¡¡in¡¡mon¡¡to¡¡solve¡¡a¡¡particular¡¡problem¡£¡¡To¡¡demonstrate¡¡the¡¡concepts£»¡¡we¡¡will¡¡create¡¡¡¡

a¡¡simple¡¡currency¡¡exchange¡¡application¡£¡¡This¡¡application¡¡will¡¡use¡¡object¡­oriented¡¡programming£»¡¡¡¡

a¡¡powerful¡¡set¡¡of¡¡techniques¡¡mon¡¡in¡¡modern¡¡programming¡¡languages¡¡such¡¡as¡¡Visual¡¡Basic¡£¡¡

¡¡¡¡¡¡¡¡¡¡In¡¡this¡¡chapter£»¡¡you¡¯ll¡¡learn¡¡about¡¡the¡¡following¡¡topics£º¡¡



¡¡¡¡¡¡¡¡¡¡Object¡­oriented¡¡programming£º¡¡Object¡­oriented£»¡¡often¡¡abbreviated¡¡as¡¡OO£»¡¡refers¡¡to¡¡a¡¡way¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡building¡¡applications¡¡using¡¡instantiated¡¡types¡£¡¡First£»¡¡you¡¡define¡¡the¡¡type¡¡and¡¡its¡¡behavior¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡Then£»¡¡when¡¡instantiated£»¡¡the¡¡type¡¡has¡¡a¡¡state¡£¡¡When¡¡you¡¡are¡¡developing£»¡¡you¡¡don¡¯t¡¡know¡¡¡¡

¡¡¡¡¡¡¡¡¡¡the¡¡state¡¡of¡¡the¡¡object£»¡¡so¡¡you¡¡can¡¡only¡¡guess¡¡at¡¡it¡£¡¡



¡¡¡¡¡¡¡¡¡¡Data¡¡member¡¡scopes£º¡¡Types¡¡have¡¡methods£»¡¡and¡¡methods¡¡can¡¡be¡¡called¡¡by¡¡other¡¡types¡£¡¡But¡¡¡¡

¡¡¡¡¡¡¡¡¡¡do¡¡you¡¡want¡¡to¡¡let¡¡all¡¡types¡¡call¡¡all¡¡of¡¡a¡¡type¡¯s¡¡methods£¿¡¡Think¡¡of¡¡it¡¡as¡¡follows¡£¡¡When¡¡you¡¡are¡¡¡¡

¡¡¡¡¡¡¡¡¡¡at¡¡a¡¡party£»¡¡do¡¡you¡¡want¡¡to¡¡allow¡¡everyone¡¡to¡¡grab¡¡into¡¡your¡¡pockets£¿¡¡No£»¡¡you¡¡want¡¡to¡¡control¡¡¡¡

¡¡¡¡¡¡¡¡¡¡access¡¡to¡¡your¡¡pockets£»¡¡just¡¡as¡¡you¡¡want¡¡to¡¡control¡¡access¡¡to¡¡your¡¡type¡¯s¡¡methods¡£¡¡



¡¡¡¡¡¡¡¡¡¡Properties£º¡¡There¡¡are¡¡methods£»¡¡and¡¡there¡¡are¡¡properties¡£¡¡Methods¡¡are¡¡supposed¡¡to¡¡do¡¡things¡¡¡¡

¡¡¡¡¡¡¡¡¡¡to¡¡a¡¡type¡£¡¡Properties¡¡are¡¡external¡¡state¡¡representations¡¡of¡¡a¡¡type¡£¡¡



¡¡¡¡¡¡¡¡¡¡Base¡¡classes£º¡¡The¡¡term¡¡base¡¡class¡¡denotes¡¡mon¡¡functionality¡£¡¡We¡¡use¡¡the¡¡word¡¡¡¡base£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡because¡¡in¡¡object¡­oriented¡¡programming£»¡¡hierarchy¡¡is¡¡defined¡¡from¡¡the¡¡base¡¡upwards¡£¡¡We¡¡¡¡

¡¡¡¡¡¡¡¡¡¡use¡¡the¡¡word¡¡class£»¡¡because¡¡class¡¡is¡¡the¡¡basic¡¡type¡¡that¡¡contains¡¡functionality¡£¡¡



¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡begin¡¡with¡¡some¡¡background¡¡on¡¡how¡¡currency¡¡exchange¡¡works£»¡¡which¡¡applies¡¡to¡¡the¡¡¡¡

currency¡¡converter¡¡application¡¡we¡¯ll¡¡develop¡¡in¡¡this¡¡chapter¡¡to¡¡demonstrate¡¡object¡­oriented¡¡¡¡

programming¡¡concepts¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡135¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡158¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

136¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡6¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡T¡¡HE¡¡¡¡¡¡B¡¡AS¡¡IC¡¡S¡¡¡¡O¡¡F¡¡¡¡¡¡OB¡¡J¡¡E¡¡CT¡¡OR¡¡I¡¡E¡¡N¡¡T¡¡E¡¡D¡¡¡¡¡¡P¡¡R¡¡O¡¡G¡¡R¡¡AM¡¡M¡¡IN¡¡G¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Understanding¡¡Currency¡¡Spreads¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡chapter¡¯s¡¡sample¡¡application¡¡deals¡¡with¡¡exchanging¡¡different¡¡currencies¡£¡¡Did¡¡you¡¡know¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡when¡¡you¡¡exchange¡¡one¡¡currency¡¡for¡¡another£»¡¡you¡¡never¡¡need¡¡to¡¡pay¡¡a¡¡processing¡¡fee£¿¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Whether¡¡you¡¡are¡¡exchanging¡¡currencies¡¡at¡¡some¡¡airport¡¡or¡¡on¡¡an¡¡exchange£»¡¡you¡¡should¡¡not¡¡be¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡charged¡¡any¡¡processing¡¡fees¡£¡¡It¡¡makes¡¡you¡¡wonder¡¡how¡¡people¡¡earn¡¡money¡¡by¡¡accepting¡¡one¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡currency¡¡and¡¡then¡¡giving¡¡out¡¡another¡¡currency¡£¡¡The¡¡answer¡¡lies¡¡in¡¡how¡¡currency¡¡exchange¡¡works¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡dealing¡¡with¡¡currencies£»¡¡you¡¡are¡¡always¡¡dealing¡¡with¡¡currency¡¡pairs¡£¡¡This¡¡is¡¡different¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡from¡¡something¡¡like¡¡buying¡¡a¡¡stock£»¡¡when¡¡you¡¡are¡¡dealing¡¡with¡¡only¡¡that¡¡stock¡£¡¡A¡¡currency¡¡by¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡itself¡¡is¡¡actually¡¡quite¡¡useless¡£¡¡Suppose¡¡you¡¡have¡¡a¡¡100¡¡in¡¡your¡¡hand¡£¡¡What¡¡will¡¡it¡¡be¡¡worth¡¡one¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡year¡¡from¡¡now£¿¡¡The¡¡answer¡¡is¡¡simple£º¡¡100¡£¡¡Yes£»¡¡you¡¡can¡¡argue¡¡that¡¡the¡¡100¡¡will¡¡not¡¡buy¡¡as¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡much¡¡next¡¡year£»¡¡but¡¡that¡¡would¡¡be¡¡plicating¡¡the¡¡issue¡¡with¡¡concerns¡¡not¡¡related¡¡to¡¡this¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡discussion¡£¡¡The¡¡fact¡¡is¡¡that¡¡if¡¡you¡¡have¡¡100¡¡dollars£»¡¡100¡¡yen£»¡¡100¡¡euros£»¡¡and¡¡so¡¡on¡¡into¡¡infinite¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡time£»¡¡you¡¡will¡¡always¡¡have¡¡100¡¡currency¡¡units¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Currency¡¡exchange¡¡involves¡¡paring¡¡one¡¡currency¡¡to¡¡another¡¡currency¡£¡¡The¡¡value¡¡of¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡currency¡¡is¡¡what¡¡one¡¡person¡¡would¡¡give¡¡in¡¡parison¡¡to¡¡another¡¡currency¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Foreign¡¡exchange¡¡£¨forex£©¡¡market¡¡traders¡¡make¡¡their¡¡money¡¡by¡¡dealing¡¡in¡¡spreads¡£¡¡Spreads¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡tricky¡¡because£»¡¡as¡¡the¡¡exchange¡¡rate¡¡moves¡¡up¡¡or¡¡down£»¡¡so¡¡does¡¡the¡¡spread¡£¡¡For¡¡example£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡hotels¡¡always¡¡give¡¡you¡¡horrible¡¡rates£»¡¡and¡¡you¡¡may¡¡wonder¡¡why¡¡they¡¡are¡¡ripping¡¡you¡¡off¡£¡¡But¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡hotels¡¡are¡¡not¡¡ripping¡¡you¡¡off£»¡¡they¡¡are¡¡hedging¡¡themselves¡¡on¡¡the¡¡safe¡¡side¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Consider¡¡the¡¡following¡¡example¡¡of¡¡a¡¡spread£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡EUR¡£USD¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£4686¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£4687¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡EUR¡£USD¡¡term¡¡means¡¡you¡¡are¡¡converting¡¡one¡¡euro¡¡£¨EUR£©¡¡into¡¡a¡¡number¡¡of¡¡US¡¡dollars¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨USD£©¡£¡¡The¡¡first¡¡number¡¡is¡¡the¡¡bid£»¡¡which¡¡means¡¡that¡¡a¡¡trader¡¡is¡¡willing¡¡to¡¡give¡¡1¡£4686¡¡US¡¡dollars¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡for¡¡every¡¡euro¡£¡¡The¡¡second¡¡number¡¡is¡¡saying¡¡a¡¡trader¡¡wants¡¡1¡£4687¡¡US¡¡dollars¡¡for¡¡every¡¡euro¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Essentially£»¡¡the¡¡buyer¡¡and¡¡seller¡¡are¡¡0¡£0001¡¡US¡¡dollars¡¡apart¡£¡¡The¡¡exchange¡¡spread¡¡is¡¡normal£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡it¡¡moves¡¡around¡¡because¡¡some¡¡might¡¡be¡¡willing¡¡to¡¡sell¡¡at¡¡a¡¡lower¡¡conversion¡¡rate£»¡¡and¡¡others¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡might¡¡be¡¡willing¡¡to¡¡buy¡¡at¡¡a¡¡higher¡¡conversion¡¡rate¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡say¡¡one¡¡day¡¡you¡¡enter¡¡a¡¡hotel¡¡in¡¡Austria¡¡on¡¡a¡¡skiing¡¡holiday¡£¡¡In¡¡your¡¡hand£»¡¡you¡¡have¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1£»000¡¡US¡¡dollars£»¡¡but¡¡Austria¡¡belongs¡¡to¡¡the¡¡European¡¡Union¡¡£¨EU£©¡£¡¡To¡¡buy¡¡anything¡¡in¡¡the¡¡EU¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡zone£»¡¡you¡¡need¡¡euros¡£¡¡Being¡¡clever£»¡¡you¡¡decide¡¡to¡¡go¡¡on¡¡the¡¡Internet¡¡and¡¡check¡¡out¡¡the¡¡going¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡spread¡£¡¡It¡¡turns¡¡out¡¡to¡¡be¡¡the¡¡one¡¡you¡¯ve¡¡just¡¡seen¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Standing¡¡in¡¡the¡¡hotel¡¡foyer£»¡¡you¡¡have¡¡US¡¡dollars¡¡in¡¡your¡¡pocket¡¡and¡¡you¡¡need¡¡to¡¡buy¡¡euros¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Thus£»¡¡you¡¡will¡¡need¡¡to¡¡go¡¡in¡¡the¡¡direction¡¡USD¡£EUR¡£¡¡The¡¡way¡¡to¡¡do¡¡that¡¡is¡¡to¡¡divide¡¡one¡¡by¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡posted¡¡spread¡¡values¡£¡¡This¡¡calculation¡¡gives¡¡the¡¡following¡¡conversion¡¡rates£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡USD¡£EUR¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡0¡£6809¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡0¡£6808¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡numbers¡¡are¡¡a¡¡bit¡¡wrong£»¡¡because¡¡the¡¡buyer¡¡is¡¡willing¡¡to¡¡give¡¡a¡¡higher¡¡value¡¡than¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡seller¡£¡¡Granted£»¡¡this¡¡happens¡¡at¡¡times¡¡on¡¡the¡¡forex¡¡markets£»¡¡but¡¡here£»¡¡it¡¯s¡¡because¡¡we¡¡used¡¡a¡¡raw¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡conversion¡¡of¡¡EUR¡£USD¡£¡¡The¡¡market¡¡might¡¡be¡¡a¡¡bit¡¡higher¡¡and¡¡lower£»¡¡but¡¡generally¡¡speaking£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡have¡¡a¡¡feeling¡¡of¡¡what¡¡to¡¡expect¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡advance¡¡to¡¡the¡¡hotel¡¡desk£»¡¡and¡¡you¡¡kindly¡¡ask¡¡what¡¡the¡¡going¡¡rate¡¡is¡¡for¡¡US¡¡dollars¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡euros¡£¡¡The¡¡concierge¡¡gives¡¡the¡¡following¡¡exchange¡¡rate£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡159¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡A¡¡PT¡¡E¡¡R¡¡¡¡¡¡6¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡T¡¡HE¡¡¡¡¡¡B¡¡AS¡¡IC¡¡S¡¡¡¡O¡¡F¡¡¡¡¡¡O¡¡B¡¡J¡¡E¡¡CT¡¡OR¡¡I¡¡E¡¡N¡¡TE¡¡D¡¡¡¡¡¡P¡¡R¡¡O¡¡G¡¡R¡¡AM¡¡M¡¡IN¡¡G¡¡137¡¡



USD¡£EUR¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡0¡£65120¡¡



EUR¡£USD¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£5010¡¡



¡¡¡¡¡¡¡¡¡¡Doing¡¡your¡¡calculations£»¡¡this¡¡rate¡¡doesn¡¯t¡¡seem¡¡right¡£¡¡The¡¡hotel¡¡is¡¡giving¡¡you¡¡651¡£20¡¡euros¡¡¡¡

for¡¡your¡¡1£»000¡¡US¡¡dollars£»¡¡but¡¡the¡¡forex¡¡market¡¡clearly¡¡says¡¡the¡¡traders¡¡would¡¡be¡¡willing¡¡to¡¡give¡¡¡¡

you¡¡680¡£91¡¡euros¡£¡¡The¡¡hotel¡¡appears¡¡to¡¡be¡¡ripping¡¡you¡¡off¡¡by¡¡approximately¡¡29¡¡euros¡£¡¡But¡¡the¡¡¡¡

hotel¡¡is¡¡not¡¡ripping¡¡you¡¡off£»¡¡rather£»¡¡it¡¡is¡¡hedging¡¡its¡¡risks¡£¡¡The¡¡spot¡¡conversion¡¡rates¡¡will¡¡go¡¡up¡¡¡¡

and¡¡down¡¡during¡¡the¡¡day£»¡¡and¡¡the¡¡hotel¡¡is¡¡not¡¡in¡¡the¡¡business¡¡of¡¡exchanging¡¡money¡£¡¡The¡¡hotel¡¡¡¡

is¡¡in¡¡the¡¡business¡¡of¡¡giving¡¡you¡¡room¡¡and¡¡board¡£¡¡The¡¡hotel¡¡managers¡¡need¡¡to¡¡make¡¡sure¡¡that¡¡¡¡

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