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

µÚ59ÕÂ

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ59ÕÂ

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

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






¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#Else¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡default¡¡code¡¡block¡¡that¡¡is¡¡included¡¡if¡¡the¡¡other¡¡#If¡¡statements¡¡did¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡not¡¡trigger¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#Region¡¡and¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡These¡¡have¡¡absolutely¡¡nothing¡¡to¡¡do¡¡with¡¡the¡¡pilation¡¡of¡¡the¡¡source¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#EndRegion¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡£¡¡They¡¡are¡¡used¡¡by¡¡Visual¡¡Studio¡¡to¡¡create¡¡regions¡¡of¡¡source¡¡code¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡can¡¡be¡¡¡°folded¡£¡±¡¡Folding¡¡means¡¡to¡¡collapse¡¡a¡¡block¡¡code¡¡out¡¡of¡¡sight¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡temporarily¡£¡¡Source¡¡code¡¡files¡¡can¡¡be¡¡bee¡¡long£»¡¡and¡¡constantly¡¡paging¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡up¡¡and¡¡down¡¡bees¡¡tedious¡£¡¡By¡¡folding¡¡the¡¡code£»¡¡you¡¡are¡¡reducing¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡amount¡¡of¡¡times¡¡that¡¡you¡¡need¡¡to¡¡page¡¡up¡¡and¡¡down£»¡¡even¡¡though¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡still¡¡exists¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡example¡¡demonstrates¡¡how¡¡to¡¡use¡¡the¡¡preprocessor¡¡directives¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#Const¡¡ACTIVATE_1¡¡=¡¡True¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Namespace¡¡TestDefine¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Example¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#If¡¡ACTIVATE_1¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_dataMember¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#ElseIf¡¡Not¡¡NO_ACTIVATE_10¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_dataMember3¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#Else¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_defaultValue¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#End¡¡If¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Namespace¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡general£»¡¡you¡¡will¡¡use¡¡preprocessor¡¡directives¡¡when¡¡you¡¡are¡¡building¡¡debug¡¡mode¡¡or¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡release¡¡mode¡¡code¡£¡¡Debug¡¡mode¡¡means¡¡that¡¡the¡¡code¡¡is¡¡piled¡¡such¡¡that¡¡it¡¡can¡¡be¡¡debugged¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡analyzed¡¡using¡¡pretty¡¡symbols¡£¡¡Release¡¡mode¡¡means¡¡when¡¡the¡¡code¡¡is¡¡piled£»¡¡the¡¡code¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡can¡¡still¡¡be¡¡debugged£»¡¡but¡¡the¡¡pretty¡¡symbols¡¡are¡¡missing¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡Visual¡¡Basic¡¡Express¡¡does¡¡not¡¡give¡¡you¡¡the¡¡flexibility¡¡to¡¡choose¡¡debug¡¡mode¡¡or¡¡release¡¡mode¡¡for¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡development¡£¡¡To¡¡get¡¡this¡¡feature£»¡¡you¡¡need¡¡the¡¡full¡¡version¡¡of¡¡Visual¡¡Studio¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Think¡¡of¡¡the¡¡pretty¡¡symbols¡¡as¡¡milestones¡¡on¡¡the¡¡road¡£¡¡Every¡¡time¡¡your¡¡code¡¡executes¡¡in¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡debug¡¡mode£»¡¡the¡¡code¡¡is¡¡saying£»¡¡¡°You¡¡are¡¡now¡¡calling¡¡this¡¡method¡¡in¡¡this¡¡source¡¡code¡¡file£»¡±¡¡or¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡°Oops£»¡¡that¡¡property¡¡code¡¡in¡¡the¡¡source¡¡code¡¡file¡¡is¡¡not¡¡working¡¡properly¡£¡±¡¡In¡¡release¡¡mode£»¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pretty¡¡symbols¡¡are¡¡more¡¡like¡¡road¡¡signs¡¡saying£»¡¡¡°Place¡¡X¡¡y¡¡Miles/Kilometers¡£¡±¡¡The¡¡signs¡¡help¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡181¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



guide¡¡you£»¡¡but¡¡the¡¡information¡¡you¡¡get¡¡from¡¡them¡¡is¡¡very¡¡limited£»¡¡that¡¡is£»¡¡you¡¡don¡¯t¡¡know¡¡which¡¡¡¡

towns¡¡you¡¯re¡¡passing¡£¡¡



More¡¡Property¡¡Scope¡¡Details¡¡



In¡¡this¡¡chapter¡¯s¡¡examples£»¡¡the¡¡Get¡¡and¡¡Set¡¡parts¡¡of¡¡the¡¡properties¡¡always¡¡had¡¡the¡¡same¡¡scope¡£¡¡¡¡

However£»¡¡properties¡¡can¡¡have¡¡mixed¡¡scope£»¡¡that¡¡is£»¡¡the¡¡Get¡¡and¡¡Set¡¡parts¡¡can¡¡have¡¡different¡¡¡¡

scopes¡£¡¡Scope¡¡splitting¡¡works¡¡only¡¡if¡¡you¡¡specify¡¡both¡¡the¡¡Get¡¡and¡¡Set¡¡parts¡¡of¡¡the¡¡property¡£¡¡The¡¡¡¡

idea¡¡behind¡¡splitting¡¡the¡¡scope¡¡is¡¡to¡¡enable¡¡the¡¡implementation¡¡of¡¡the¡¡logic¡¡where¡¡classes¡¡in¡¡the¡¡¡¡

inheritance¡¡chain¡¡are¡¡allowed¡¡to¡¡assign¡¡a¡¡property£»¡¡and¡¡classes¡¡external¡¡to¡¡the¡¡inheritance¡¡¡¡

chain¡¡are¡¡allowed¡¡only¡¡to¡¡read¡¡the¡¡property¡£¡¡The¡¡following¡¡is¡¡an¡¡example¡¡where¡¡a¡¡property¡¡is¡¡¡¡

declared¡¡as¡¡Public¡¡and¡¡the¡¡assignment¡¡of¡¡the¡¡property¡¡is¡¡¡¡Protected¡£¡¡



Class¡¡PropertyScopeExample¡¡

¡¡¡¡¡¡¡¡Private¡¡_value¡¡As¡¡Integer¡¡



¡¡¡¡¡¡¡¡Public¡¡Property¡¡Value£¨£©¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Protected¡¡Set£¨ByVal¡¡value¡¡As¡¡Integer£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_value¡¡=¡¡value¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Set¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_value¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡End¡¡Property¡¡

End¡¡Class¡¡



The¡¡MustOverride¡¡Keyword¡¡



In¡¡this¡¡chapter¡¯s¡¡example£»¡¡the¡¡keyword¡¡MustInherit¡¡was¡¡used¡¡to¡¡declare¡¡a¡¡class¡¡that¡¡could¡¡be¡¡¡¡

referenced£»¡¡but¡¡not¡¡instantiated¡£¡¡It¡¡is¡¡also¡¡possible¡¡to¡¡define¡¡methods¡¡that¡¡need¡¡to¡¡be¡¡imple

mented¡£¡¡In¡¡Visual¡¡Basic£»¡¡to¡¡require¡¡a¡¡derived¡¡class¡¡to¡¡implement¡¡the¡¡method£»¡¡you¡¡use¡¡MustOverride¡£¡¡¡¡

The¡¡idea¡¡behind¡¡declaring¡¡methods¡¡that¡¡need¡¡to¡¡be¡¡overridden¡¡is¡¡that¡¡it¡¡allows¡¡a¡¡developer¡¡to¡¡¡¡

define¡¡an¡¡intention¡¡in¡¡a¡¡base¡¡class¡¡that¡¡can¡¡then¡¡be¡¡implemented¡¡in¡¡the¡¡subclass¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡implementation¡¡of¡¡HotelCurrencyTrader¡¡and¡¡ActiveCurrencyTrader£»¡¡two¡¡methods¡¡¡¡

were¡¡defined£º¡¡ConvertTo£¨£©¡¡and¡¡ConvertFrom£¨£©¡£¡¡A¡¡developer¡¡could¡¡e¡¡to¡¡the¡¡conclusion¡¡that¡¡¡¡

the¡¡methods¡¡are¡¡mon¡¡to¡¡both¡¡classes£»¡¡and¡¡thus¡¡they¡¡could¡¡be¡¡defined¡¡in¡¡the¡¡base¡¡class¡¡¡¡

CurrencyTrader¡£¡¡That¡¡is¡¡not¡¡a¡¡bad¡¡idea¡£¡¡Let¡¯s¡¡revisit¡¡the¡¡CurrencyTrader¡¡class¡¡and¡¡see¡¡how¡¡these¡¡¡¡

two¡¡methods¡¡could¡¡be¡¡added¡¡to¡¡CurrencyTrader¡¡as¡¡MustOverride¡¡methods¡£¡¡



Public¡¡MustInherit¡¡Class¡¡CurrencyTrader¡¡

¡¡¡¡¡¡¡¡Private¡¡_exchangeRate¡¡As¡¡Double¡¡



¡¡¡¡¡¡¡¡Protected¡¡Property¡¡ExchangeRate£¨£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_exchangeRate¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Set¡¡£¨ByVal¡¡Value¡¡As¡¡Double£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_exchangeRate¡¡=¡¡Value¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Set¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡182¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Protected¡¡Function¡¡ConvertValue£¨ByVal¡¡input¡¡As¡¡Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_exchangeRate¡¡*¡¡input¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Protected¡¡Function¡¡ConvertValueInverse£¨ByVal¡¡input¡¡As¡¡Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡input¡¡/¡¡_exchangeRate¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡MustOverride¡¡Function¡¡ConvertTo£¨ByVal¡¡value¡¡As¡¡Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡MustOverride¡¡Function¡¡ConvertFrom£¨ByVal¡¡value¡¡As¡¡Double£©¡¡As¡¡Double¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡MustOverride¡¡method¡¡is¡¡declared¡¡without¡¡an¡¡implementation¡£¡¡Any¡¡class¡¡that¡¡subclasses¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CurrencyTrader¡¡is¡¡required¡¡to¡¡implement¡¡ConvertTo£¨£©¡¡and¡¡ConvertFrom£¨£©¡£¡¡In¡¡the¡¡case¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡HotelCurrencyTrader¡¡and¡¡ActiveCurrencyTrader£»¡¡this¡¡is¡¡not¡¡a¡¡problem£»¡¡because¡¡the¡¡methods¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡already¡¡implemented¡£¡¡However£»¡¡the¡¡methods¡¡need¡¡to¡¡be¡¡changed¡¡slightly£»¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡ConvertTo£¨ByVal¡¡value¡¡As¡¡Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡¡£¡¡¡£¡¡¡£¡¡¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡ConvertFrom£¨ByVal¡¡value¡¡As¡¡Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡¡£¡¡¡£¡¡¡£¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡slight¡¡change¡¡is¡¡the¡¡addition¡¡of¡¡the¡¡keyword¡¡Overrides¡¡to¡¡indicate¡¡that¡¡the¡¡ConvertTo£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡ConvertFrom£¨£©¡¡methods¡¡in¡¡HotelCurrencyTrader¡¡and¡¡ActiveCurrencyTrader¡¡override¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡functionality¡¡in¡¡CurrencyTrader¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡While¡¡you¡¡have¡¡seen¡¡all¡¡of¡¡the¡¡technical¡¡aspects£»¡¡the¡¡bigger¡¡question¡¡is¡¡why¡¡you¡¡would¡¡do¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡in¡¡the¡¡first¡¡place¡£¡¡Let¡¯s¡¡go¡¡back¡¡to¡¡the¡¡implementation¡¡of¡¡ActiveCurrencyTrader£»¡¡which¡¡has¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡no¡¡MustOverride¡¡method¡¡implementations¡£¡¡To¡¡use¡¡the¡¡class¡¡and¡¡the¡¡method¡¡ConvertTo£¨£©£»¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡would¡¡write¡¡the¡¡following¡¡code¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡cls¡¡As¡¡ActiveCurrencyTrader¡¡=¡¡New¡¡ActiveCurrencyTrader£¨1¡£46£»¡¡¡¨USD¡¨£»¡¡¡¨EUR¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡converted¡¡As¡¡Double¡¡=¡¡cls¡£ConvertTo£¨100¡£0£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imagine¡¡the¡¡situation¡¡where¡¡the¡¡values¡¡to¡¡convert¡¡to¡¡and¡¡from¡¡are¡¡text¡£¡¡To¡¡keep¡¡things¡¡general£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡would¡¡write¡¡the¡¡following¡¡code¡¡£¨which¡¡takes¡¡the¡¡value¡¡from¡¡a¡¡text¡¡box¡¡in¡¡a¡¡Windows¡¡form£©¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Function¡¡ConvertToTextField£¨ByVal¡¡cls¡¡As¡¡ActiveCurrencyTrader£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡cls¡£ConvertTo£¨Double¡£Parse£¨text1¡£Text£©£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡implementation¡¡of¡¡ConvertToTextField£¨£©¡¡makes¡¡one¡¡major¡¡mistake¡¡in¡¡that¡¡it¡¡assumes¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡you¡¡will¡¡always¡¡be¡¡converting¡¡a¡¡currency¡¡using¡¡the¡¡ActiveCurrencyTrader¡¡implementation¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡wanted¡¡to¡¡use¡¡the¡¡class¡¡HotelCurrencyTrader£»¡¡you¡¡would¡¡need¡¡to¡¡implement¡¡another¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡method¡¡with¡¡a¡¡parameter¡¡of¡¡type¡¡HotelCurrencyTrader¡£¡¡

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

Äã¿ÉÄÜϲ»¶µÄ