VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ41²¿·Ö
°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡for¡¡euros£»¡¡they¡¡don¡¯t¡¡lose¡¡money¡¡in¡¡the¡¡¡¡
process¡£¡¡They¡¡ensure¡¡this¡¡by¡¡giving¡¡you¡¡less¡¡money¡£¡¡
¡¡¡¡¡¡¡¡¡¡Whenever¡¡you¡¡exchange¡¡monies£»¡¡you¡¡should¡¡always¡¡look¡¡at¡¡the¡¡spreads¡£¡¡Sometimes¡¡the¡¡¡¡
spreads¡¡are¡¡good£»¡¡sometimes¡¡they¡¡are¡¡horrible¡£¡¡I¡¡have¡¡found¡¡the¡¡best¡¡spreads¡¡are¡¡at¡¡the¡¡banks¡£¡¡¡¡
It¡¡is¡¡a¡¡bit¡¡more¡¡work¡¡to¡¡get¡¡money¡¡from¡¡your¡¡home¡¡bank£»¡¡but¡¡usually¡¡worth¡¡the¡¡effort¡£¡¡Another¡¡¡¡
option¡¡is¡¡to¡¡pull¡¡the¡¡money¡¡from¡¡your¡¡credit¡¡card£»¡¡however£»¡¡sometimes¡¡credit¡¡cards¡¡charge¡¡¡¡
interest¡¡on¡¡the¡¡money¡¡you¡¡withdrew¡£¡¡
¡¡¡¡¡¡¡¡¡¡Now¡¡that¡¡you¡¡have¡¡an¡¡idea¡¡of¡¡what¡¯s¡¡involved¡¡in¡¡currency¡¡exchange£»¡¡let¡¯s¡¡see¡¡what¡¡our¡¡¡¡
sample¡¡application¡¡will¡¡do¡£¡¡
Organizing¡¡the¡¡Currency¡¡Exchange¡¡Application¡¡
The¡¡currency¡¡application¡¡takes¡¡a¡¡number¡¡of¡¡currency¡¡units¡¡and¡¡converts¡¡it¡¡to¡¡a¡¡number¡¡of¡¡other¡¡¡¡
currency¡¡units¡£¡¡The¡¡application¡¡will¡¡implement¡¡the¡¡following¡¡features£º¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡Accept¡¡and¡¡store¡¡a¡¡currency¡¡exchange¡¡rate¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡Store¡¡the¡¡currency¡¡unit¡¡identifiers¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡Convert¡¡to¡¡a¡¡currency¡¡and¡¡back¡¡to¡¡the¡¡original¡¡currency¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡Distinguish¡¡between¡¡active¡¡currency¡¡traders¡¡and¡¡hotel¡¡currency¡¡traders¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡Implement¡¡a¡¡spread¡¡for¡¡hotel¡¡currency¡¡traders¡¡
¡¡¡¡¡¡¡¡¡¡As¡¡in¡¡the¡¡examples¡¡in¡¡the¡¡previous¡¡chapters£»¡¡the¡¡project¡¡structure¡¡of¡¡the¡¡currency¡¡applica
tion¡¡will¡¡consist¡¡of¡¡two¡¡projects£º¡¡a¡¡console¡¡testing¡¡application£»¡¡named¡¡TestCurrencyTrader£»¡¡and¡¡¡¡
a¡¡library¡¡ponent£»¡¡named¡¡CurrencyTrader£»¡¡which¡¡contains¡¡the¡¡functionality¡¡of¡¡the¡¡hotel¡¡¡¡
trader¡¡and¡¡the¡¡active¡¡trader¡£¡¡
Writing¡¡Tests¡¡for¡¡the¡¡¡¡
Currency¡¡Exchange¡¡Application¡¡¡¡
Since¡¡we¡¡don¡¯t¡¡know¡¡exactly¡¡how¡¡the¡¡implementation¡¡will¡¡appear£»¡¡let¡¯s¡¡start¡¡by¡¡writing¡¡some¡¡¡¡
tests¡¡that¡¡will¡¡use¡¡our¡¡implementation¡£¡¡We¡¡want¡¡to¡¡build¡¡the¡¡application¡¡incrementally£»¡¡so¡¡we¡¯ll¡¡¡¡
write¡¡some¡¡tests£»¡¡write¡¡some¡¡code£»¡¡test¡¡the¡¡code£»¡¡and¡¡continue¡£¡¡The¡¡overall¡¡big¡¡picture¡¡is¡¡to¡¡be¡¡¡¡
able¡¡to¡¡convert¡¡from¡¡one¡¡currency¡¡to¡¡another¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡160¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
138¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Getting¡¡Started¡¡with¡¡Structural¡¡Code¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡At¡¡the¡¡heart¡¡of¡¡the¡¡application¡¡are¡¡an¡¡exchange¡¡rate£»¡¡currency¡¡units£»¡¡and¡¡a¡¡calculation¡¡that¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡bines¡¡the¡¡exchange¡¡rate¡¡with¡¡the¡¡currency¡¡units¡£¡¡Thus£»¡¡a¡¡logical¡¡first¡¡step¡¡would¡¡be¡¡to¡¡write¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡test¡¡code¡¡that¡¡bines¡¡these¡¡elements£»¡¡something¡¡like¡¡this£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡cls¡¡As¡¡CurrencyTrader¡¡=¡¡New¡¡CurrencyTrader£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cls¡£ExchangeRate¡¡=¡¡1¡£46¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡haveUSD¡¡As¡¡Double¡¡=¡¡100¡£0¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡getEUR¡¡As¡¡Double¡¡=¡¡cls¡£Convert£¨haveUSD£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Converted¡¡¡¨¡¡&¡¡haveUSD¡¡&¡¡¡¨¡¡USD¡¡to¡¡¡¨¡¡&¡¡getEUR£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡code¡¡is¡¡unique¡¡in¡¡that¡¡the¡¡test¡¡code¡¡has¡¡all¡¡of¡¡the¡¡responsibility¡¡of¡¡making¡¡sure¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡correct¡¡data¡¡is¡¡assigned¡¡to¡¡the¡¡structure¡£¡¡To¡¡clarify¡¡this£»¡¡here¡¡is¡¡the¡¡same¡¡code¡¡with¡¡random¡¡vari
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡able¡¡names¡¡used¡¡instead¡¡of¡¡the¡¡identifiers¡¡for¡¡the¡¡currency¡¡variables£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡cls¡¡As¡¡CurrencyTrader¡¡=¡¡New¡¡CurrencyTrader£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cls¡£ExchangeRate¡¡=¡¡1¡£46¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡ukfkisd¡¡As¡¡Double¡¡=¡¡100¡£0¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡didkfdbnfd¡¡As¡¡Double¡¡=¡¡cls¡£Convert£¨ukfkisd£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Converted¡¡¡¨¡¡&¡¡ukfkisd¡¡&¡¡¡¨¡¡USD¡¡to¡¡¡¨¡¡&¡¡didkfdbnfd£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡code¡¡is¡¡structural£»¡¡rather¡¡than¡¡architectural¡£¡¡Structural¡¡code¡¡is¡¡code¡¡that¡¡requires¡¡an¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡intelligent¡¡programmer¡ªa¡¡programmer¡¡who¡¡knows¡¡what¡¡the¡¡individual¡¡items¡¡mean¡£¡¡In¡¡this¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡case£»¡¡the¡¡programmer¡¡must¡¡know¡¡that¡¡the¡¡Convert£¨£©¡¡method¡¡converts¡¡from¡¡USD¡¡to¡¡EUR¡¡and¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡therefore¡¡needs¡¡to¡¡supply¡¡the¡¡correct¡¡values¡¡at¡¡the¡¡correct¡¡time¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Architectural¡¡code£»¡¡on¡¡the¡¡other¡¡hand£»¡¡is¡¡more¡¡idiot¡proof¡¡and¡¡requires¡¡less¡¡knowledge£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡because¡¡many¡¡parts¡¡are¡¡encapsulated¡£¡¡The¡¡user¡¡needs¡¡to¡¡understand¡¡only¡¡how¡¡to¡¡use¡¡the¡¡classes¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Put¡¡another¡¡way£»¡¡structural¡¡code¡¡is¡¡knowing¡¡how¡¡to¡¡add¡¡two¡¡numbers¡£¡¡Architectural¡¡code¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡knowing¡¡how¡¡to¡¡punch¡¡in¡¡the¡¡two¡¡numbers¡¡and¡¡hit¡¡the¡¡plus¡¡sign¡¡on¡¡a¡¡calculator¡£¡¡You¡¡can¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡argue¡¡that¡¡by¡¡not¡¡knowing¡¡how¡¡to¡¡add¡¡and¡¡relying¡¡on¡¡the¡¡calculator£»¡¡you¡¡have¡¡no¡¡idea¡¡if¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡calculator¡¡is¡¡doing¡¡its¡¡job¡¡properly¡£¡¡That¡¡is¡¡a¡¡valid¡¡point£»¡¡and¡¡that¡¡is¡¡why¡¡tests¡¡are¡¡important¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ensure¡¡that¡¡the¡¡calculator¡¡is¡¡doing¡¡its¡¡job¡¡properly¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Understanding¡¡Base¡¡Classes¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡first¡¡test¡¡code£»¡¡which¡¡is¡¡structural£»¡¡is¡¡not¡¡wrong¡£¡¡Structural¡¡code¡¡forms¡¡the¡¡basis¡¡of¡¡what¡¡is¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡called¡¡a¡¡base¡¡class¡£¡¡A¡¡base¡¡class¡¡is¡¡a¡¡class¡¡that¡¡provides¡¡certain¡¡functionality¡¡that¡¡will¡¡be¡¡reused¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡by¡¡other¡¡classes¡£¡¡In¡¡this¡¡case£»¡¡converting¡¡the¡¡currency¡¡units¡¡is¡¡functionality¡¡that¡¡we¡¡will¡¡need¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡in¡¡both¡¡the¡¡active¡¡trader¡¡and¡¡hotel¡¡trader¡£¡¡You¡¡define¡¡base¡¡classes¡¡so¡¡that¡¡you¡¡get¡¡consistent¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡behavior¡¡when¡¡performing¡¡identical¡¡operations¡£¡¡In¡¡lieu