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

µÚ47²¿·Ö

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

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

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



¡¡OR¡¡I¡¡E¡¡N¡¡TE¡¡D¡¡¡¡¡¡P¡¡R¡¡O¡¡G¡¡R¡¡AM¡¡M¡¡IN¡¡G¡¡157¡¡



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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡realExchange¡¡As¡¡Double¡¡=¡¡ExchangeRate¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ExchangeRate¡¡=¡¡realExchange¡¡£«¡¡_spread¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡retval¡¡As¡¡Double¡¡=¡¡ConvertValueInverse£¨value£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ExchangeRate¡¡=¡¡realExchange¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡retval¡¡

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

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡ConvertTo£¨£©¡¡and¡¡ConvertFrom£¨£©¡¡methods¡¡have¡¡the¡¡added¡¡logic¡¡in¡¡that¡¡the¡¡spread¡¡will¡¡¡¡

be¡¡added¡¡or¡¡subtracted¡¡from¡¡the¡¡exchange¡¡rate¡£¡¡The¡¡methods¡¡read¡¡the¡¡current¡¡exchange¡¡rate£»¡¡¡¡

assign¡¡it¡¡to¡¡a¡¡temporary¡¡variable£»¡¡define¡¡a¡¡new¡¡exchange¡¡rate¡¡taking¡¡into¡¡account¡¡the¡¡spread£»¡¡¡¡

calculate¡¡the¡¡currency£»¡¡and¡¡then¡¡reassign¡¡the¡¡exchange¡¡rate¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡ConvertTo£¨£©¡¡and¡¡ConvertFrom£¨£©¡¡methods¡¡swap¡¡values¡¡to¡¡achieve¡¡the¡¡desired¡¡calcula

tions¡£¡¡There¡¡is¡¡absolutely¡¡nothing¡¡wrong¡¡with¡¡doing¡¡this£»¡¡and¡¡you¡¡will¡¡often¡¡swap¡¡values¡¡in¡¡your¡¡¡¡

own¡¡code¡£¡¡What¡¡is¡¡important¡¡is¡¡to¡¡restrict¡¡access¡¡on¡¡what¡¡classes¡¡can¡¡do¡¡this¡£¡¡Because¡¡ExchangeRate¡¡¡¡

is¡¡a¡¡property¡¡with¡¡protected¡¡access£»¡¡it¡¡means¡¡only¡¡those¡¡classes¡¡that¡¡subclass¡¡can¡¡assign¡¡and¡¡¡¡

change¡¡the¡¡value¡¡of¡¡ExchangeRate¡£¡¡And¡¡this¡¡implies¡¡that¡¡the¡¡class¡¡doing¡¡the¡¡subclassing¡¡knows¡¡¡¡

what¡¡it¡¡is¡¡doing¡¡to¡¡the¡¡data¡£¡¡It¡¡is¡¡a¡¡valid¡¡assumption¡¡and¡¡one¡¡that¡¡you¡¡can¡¡use¡¡to¡¡your¡¡benefit¡£¡¡¡¡

The¡¡caller¡¡is¡¡not¡¡aware¡¡of¡¡this¡¡swapping£»¡¡because¡¡HotelCurrencyTrader¡¡is¡¡taking¡¡advantage¡¡of¡¡¡¡

the¡¡object¡­oriented¡¡technique¡¡to¡¡not¡¡expose¡¡the¡¡state¡¡of¡¡the¡¡type¡£¡¡

¡¡¡¡¡¡¡¡¡¡That¡¯s¡¡it¡ªwe¡¯re¡¡finished¡¡with¡¡the¡¡currency¡¡exchange¡¡application¡£¡¡For¡¡the¡¡remainder¡¡of¡¡¡¡

this¡¡chapter£»¡¡I¡¡will¡¡fill¡¡in¡¡some¡¡extra¡¡details¡¡that¡¡are¡¡important¡£¡¡



Learning¡¡More¡¡About¡¡Preprocessor¡¡Directives£»¡¡¡¡

Properties£»¡¡and¡¡the¡¡MustOverride¡¡Keyword¡¡



Some¡¡details¡¡about¡¡preprocessor¡¡directives£»¡¡properties£»¡¡and¡¡the¡¡MustOverride¡¡keyword¡¡that¡¡did¡¡¡¡

not¡¡e¡¡up¡¡in¡¡this¡¡chapter¡¯s¡¡example¡¡are¡¡worth¡¡mentioning¡£¡¡These¡¡are¡¡things¡¡you¡¡should¡¡¡¡

know¡¡about¡¡when¡¡writing¡¡your¡¡own¡¡code¡£¡¡



More¡¡Preprocessor¡¡Directive¡¡Details¡¡



Earlier¡¡in¡¡the¡¡chapter£»¡¡you¡¡saw¡¡how¡¡you¡¡can¡¡use¡¡the¡¡hash¡¡character¡¡£¨#£©¡¡and¡¡conditional¡¡state

ments¡¡to¡¡conditionally¡¡include¡¡code¡¡during¡¡pilation¡£¡¡The¡¡technical¡¡term¡¡for¡¡this¡¡jargon¡¡is¡¡¡¡

called¡¡preprocessing¡¡the¡¡code£»¡¡and¡¡the¡¡statements¡¡are¡¡called¡¡¡¡preprocessor¡¡directives¡£¡¡Table¡¡6¡­1¡¡¡¡

shows¡¡the¡¡preprocessor¡¡directives¡¡you¡¡can¡¡use¡£¡¡



Table¡¡6¡­1¡£¡¡Available¡¡Preprocessor¡¡Directives¡¡



Hash¡¡Code¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Description¡¡



#Const¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Used¡¡to¡¡define¡¡the¡¡pilation¡¡identifier£»¡¡such¡¡as¡¡the¡¡INTEGRATE_TESTS¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡identifier¡¡used¡¡in¡¡this¡¡chapter¡¯s¡¡example¡£¡¡You¡¡would¡¡define¡¡this¡¡at¡¡the¡¡top¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡a¡¡source¡¡code¡¡file¡¡to¡¡activate¡¡conditional¡¡preprocessor¡¡statements¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡used¡¡throughout¡¡the¡¡source¡¡code¡¡file¡£¡¡Using¡¡a¡¡#Const¡¡directive¡¡does¡¡not¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡span¡¡multiple¡¡source¡¡code¡¡files¡£¡¡



#If¡¡and¡¡#End¡¡If¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Used¡¡to¡¡conditionally¡¡include¡¡or¡¡not¡¡include¡¡a¡¡piece¡¡of¡¡source¡¡code¡£¡¡You¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡would¡¡use¡¡a¡¡conditional¡¡directive¡¡whenever¡¡you¡¡wanted¡¡to¡¡define¡¡source¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡configurations£»¡¡such¡¡as¡¡for¡¡debug¡¡or¡¡production¡¡builds¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡180¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Table¡¡6¡­1¡£¡¡Available¡¡Preprocessor¡¡Directives¡¡£¨Continued£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Hash¡¡Code¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Description¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#ElseIf¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Instead¡¡of¡¡a¡¡single¡¡#If¡¡block£»¡¡you¡¡could¡¡have¡¡multiple¡¡tests¡¡for¡¡code¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡inclusion¡£¡¡You¡¡would¡¡use¡¡#ElseIf¡¡when¡¡you¡¡have¡¡more¡¡than¡¡a¡¡single¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡preprocessor¡¡directive£»¡¡such¡¡as¡¡for¡¡debug£»¡¡production£»¡¡and¡¡performance¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡builds¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡#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¡¡impleme

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

Äã¿ÉÄÜϲ»¶µÄ