°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
ality¡¡of¡¡the¡¡BMW¡¡530xi¡£¡¡But¡¡here¡¡is¡¡the¡¡twist£º¡¡the¡¡functionality¡¡of¡¡the¡¡530xi¡¡Sports¡¡Wagon¡¡requires¡¡¡¡
you¡¡to¡¡get¡¡accustomed¡¡to¡¡the¡¡Sports¡¡Wagon¡£¡¡For¡¡example£»¡¡even¡¡though¡¡you¡¡press¡¡a¡¡single¡¡¡¡
button¡¡to¡¡open¡¡the¡¡trunk£»¡¡the¡¡Sports¡¡Wagon¡¯s¡¡trunk¡¡is¡¡slightly¡¡different¡¡from¡¡the¡¡trunk¡¡in¡¡the¡¡¡¡
530xi¡¡and¡¡530i£»¡¡and¡¡thus¡¡exposes¡¡the¡¡driver¡¡to¡¡a¡¡slightly¡¡different¡¡user¡¡interface¡¡and¡¡behavior¡£¡¡
¡¡¡¡¡¡¡¡¡¡When¡¡you¡¡use¡¡inheritance¡¡to¡¡overload¡¡functionality£»¡¡you¡¡are¡¡adding¡¡functionality¡¡that¡¡is¡¡¡¡
called¡¡in¡¡the¡¡same¡¡way£»¡¡but¡¡is¡¡used¡¡and¡¡behaves¡¡differently¡£¡¡With¡¡this¡¡form¡¡of¡¡inheritance£»¡¡you¡¡¡¡
don¡¯t¡¡just¡¡change¡¡behavior£»¡¡you¡¡also¡¡change¡¡the¡¡user¡¡interaction¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡In¡¡our¡¡example£»¡¡we¡¡will¡¡use¡¡inheritance¡¡to¡¡extend¡¡functionality£»¡¡and¡¡not¡¡override¡¡or¡¡overload¡£¡¡¡¡
Using¡¡Visual¡¡Basic¡¡Properties¡¡
So¡¡far£»¡¡the¡¡test¡¡code¡¡would¡¡call¡¡a¡¡data¡¡member¡¡reference£»¡¡as¡¡in¡¡this¡¡line£º¡¡
cls¡£ExchangeRate¡¡=¡¡123¡£45¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡data¡¡member¡¡could¡¡be¡¡implemented¡¡as¡¡follows£º¡¡
Public¡¡MustInherit¡¡Class¡¡CurrencyTrader¡¡
¡¡¡¡¡¡¡¡Public¡¡ExchangeRate¡¡As¡¡Double¡¡
End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡Exposing¡¡the¡¡data¡¡member¡¡using¡¡a¡¡public¡¡scope¡¡worked¡¡in¡¡previous¡¡chapters£»¡¡but¡¡we¡¡don¡¯t¡¡¡¡
really¡¡want¡¡to¡¡do¡¡this¡¡because¡¡we¡¡are¡¡exposing¡¡the¡¡internal¡¡state¡¡of¡¡the¡¡object¡£¡¡In¡¡object¡oriented¡¡¡¡
programming£»¡¡exposing¡¡the¡¡internal¡¡state¡¡is¡¡a¡¡bad¡¡idea¡¡£¨as¡¡explained¡¡in¡¡more¡¡detail¡¡shortly£©¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡164¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
142¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Rather¡¡than¡¡expose¡¡the¡¡data¡¡member¡¡publicly£»¡¡we¡¡will¡¡change¡¡the¡¡test¡¡code¡¡to¡¡use¡¡properties¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Properties¡¡also¡¡expose¡¡the¡¡internal¡¡state¡¡of¡¡an¡¡object£»¡¡but¡¡they¡¡provide¡¡a¡¡layer¡¡of¡¡abstraction¡£¡¡As¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡will¡¡learn£»¡¡some¡¡properties¡¡expose¡¡both¡¡internal¡¡state¡¡and¡¡external¡¡state¡£¡¡This¡¡is¡¡the¡¡case¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡the¡¡¡¡ExchangeRate¡¡property¡¡that¡¡we¡¡will¡¡use¡¡to¡¡access¡¡and¡¡modify¡¡the¡¡exchange¡¡rate¡£¡¡If¡¡we¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡did¡¡not¡¡use¡¡the¡¡ExchangeRate¡¡property£»¡¡we¡¡would¡¡need¡¡to¡¡create¡¡a¡¡method¡¡that¡¡assigns¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡exchange¡¡rate¡¡and¡¡a¡¡method¡¡that¡¡retrieves¡¡the¡¡exchange¡¡rate¡£¡¡The¡¡methods¡¡would¡¡behave¡¡like¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡property£»¡¡but¡¡they¡¡would¡¡not¡¡be¡¡as¡¡convenient¡¡to¡¡use¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Rewriting¡¡the¡¡Test¡¡Code¡¡to¡¡Use¡¡Properties¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡interesting¡¡thing¡¡about¡¡Visual¡¡Basic¡¡properties¡¡is¡¡that¡¡they¡¡look¡¡and¡¡behave¡¡like¡¡data¡¡members¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡means¡¡with¡¡Visual¡¡Basic¡¡properties£»¡¡the¡¡test¡¡code¡¡does¡¡not¡¡need¡¡to¡¡be¡¡rewritten£»¡¡as¡¡the¡¡test¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡still¡¡assumes¡¡a¡¡direct¡¡access¡¡to¡¡the¡¡variable¡£¡¡Consider¡¡the¡¡rewritten¡¡CurrencyTrader¡¡that¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡exposes¡¡ExchangeRate¡¡as¡¡a¡¡Visual¡¡Basic¡¡property£»¡¡shown¡¡in¡¡Figure¡¡6¡3¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Data¡¡member¡¡ExchangeRate¡¡is¡¡relabeled¡¡to¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡MustInherit¡¡Class¡¡CurrencyTrader¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_exchangeRate£»¡¡and¡¡the¡¡scope¡¡is¡¡changed¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_exchangeRate¡¡As¡¡Double¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡from¡¡public¡¡to¡¡private¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Property¡¡ExchangeRate£¨£©¡¡As¡¡Double¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_exchangeRate¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡Visual¡¡Basic¡¡property¡¡declaration¡¡looks¡¡like¡¡a¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡function¡¡declaration¡¡without¡¡the¡¡parameters£»¡¡and¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Set£¨ByVal¡¡value¡¡As¡¡Double£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡instead¡¡of¡¡Function£»¡¡Property¡¡is¡¡used¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_exchangeRate¡¡=¡¡value¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Set¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡What¡¡makes¡¡a¡¡property¡¡uniquely¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡different¡¡from¡¡a¡¡function¡¡are¡¡the¡¡Get¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡Set¡¡keywords¡¡used¡¡to¡¡return¡¡and¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡assign¡¡the¡¡value¡¡of¡¡the¡¡property¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡6¡3¡£¡¡Exposing¡¡ExchangeRate¡¡as¡¡a¡¡Visual¡¡Basic¡¡property¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡pletely¡¡fool¡¡the¡¡test£»¡¡the¡¡name¡¡of¡¡the¡¡property¡¡must¡¡be¡¡identical¡¡to¡¡the¡¡name¡¡of¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡previously¡¡declared¡¡data¡¡member¡£¡¡So¡¡that¡¡there¡¡is¡¡no¡¡identifier¡¡collision£»¡¡the¡¡data¡¡member¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ExchangeRate¡¡is¡¡renamed¡¡to¡¡_exchangeRate£»¡¡and¡¡the¡¡scope¡¡changes¡¡from¡¡public¡¡to¡¡private¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Properties¡¡look¡¡like¡¡methods¡¡without¡¡parameters£»¡¡but¡¡have¡¡a¡¡return¡¡value¡£¡¡Also£»¡¡each¡¡prop
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡erty¡¡must¡¡have¡¡at¡¡least¡¡a¡¡Get¡¡code¡¡block¡¡or¡¡a¡¡Set¡¡block¡¡£¨it¡¡can¡¡have¡¡both£©£»¡¡which¡¡are¡¡called¡¡getters¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡setters¡£¡¡If¡¡a¡¡property¡¡has¡¡only¡¡a¡¡Get¡¡code¡¡block£»¡¡you¡¡have¡¡created¡¡a¡¡read¡only¡¡property¡£¡¡If¡¡a¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡property¡¡has¡¡only¡¡a¡¡Set¡¡code¡¡block£»¡¡you¡¡have¡¡created¡¡a¡¡write¡only¡¡property¡£¡¡Within¡¡the¡¡context¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡a¡¡property£»¡¡you¡¡can¡¡have¡¡only¡¡the¡¡Get¡¡or¡¡Set¡¡keyword¡£¡¡You¡¡cannot¡¡add¡¡any¡¡other¡¡code¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡code¡¡will¡¡execute¡¡the¡¡code¡¡defined¡¡in¡¡the¡¡Get¡¡code¡¡block¡¡and¡¡retrieve¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡state¡¡from¡¡the¡¡object¡¡to¡¡the¡¡variable¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡value¡¡=¡¡cls¡£ExchangeRate¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡And¡¡the¡¡following¡¡code¡¡will¡¡execute¡¡the¡¡code¡¡in¡¡the¡¡¡¡Set¡¡code¡¡block¡¡and¡¡assign¡¡the¡¡state¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡from¡¡the¡¡variable¡¡to¡¡the¡¡object¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡165¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡143¡¡
cls¡£ExchangeRate¡¡=¡¡value¡¡
¡¡¡¡¡¡¡¡¡¡Each¡¡code¡¡block¡¡has¡¡special¡¡features¡£¡¡The¡¡Get¡¡code¡¡block¡¡must¡¡always¡¡return¡¡data¡¡to¡¡the¡¡¡¡
caller¡¡and¡¡thus¡¡requires¡¡the¡¡use¡¡of¡¡the¡¡Return¡¡keyword¡£¡¡The¡¡Set¡¡code¡¡block¡¡has¡¡no¡¡requirements¡¡¡¡
to¡¡do¡¡anything¡£¡¡However£»¡¡if¡¡you¡¡want¡¡to¡¡know¡¡what¡¡data¡¡is¡¡being¡¡passed¡¡to¡¡the¡¡property£»¡¡you¡¡¡¡
can¡¡use¡¡the¡¡value¡¡parameter¡£¡¡
Understanding¡¡the¡¡Problems¡¡with¡¡Properties¡¡
Many¡¡programmers¡¡feel¡¡that¡¡properties¡¡promote¡¡bad¡¡programming¡¡practices¡£¡¡Properties¡¡expose¡¡¡¡
the¡¡internal¡¡state¡¡of¡¡an¡¡object¡£¡¡Looking¡¡at¡¡the¡¡previous¡¡source¡¡code£»¡¡you¡¡will¡¡see¡¡that¡¡the¡¡data¡¡¡¡
member¡¡_exchangeRate¡¡has¡¡a¡¡one¡to¡one¡¡relationship¡¡to¡¡the¡¡property¡¡¡¡ExchangeRate¡£¡¡If¡¡the¡¡caller¡¡¡¡
assigns¡¡the¡¡property¡¡ExchangeRate£»¡¡then¡¡the¡¡private¡¡data¡¡member¡¡_exchangeRate¡¡is¡¡immediately¡¡¡¡
assigned¡£¡¡This¡¡exposes¡¡the¡¡internal¡¡state£»¡¡even¡¡though¡¡the¡¡exposure¡¡is¡¡indirect¡£¡¡
¡¡¡¡¡¡¡¡¡¡As¡¡an¡¡example£»¡¡say¡¡that¡¡you¡¡want¡¡to¡¡preheat¡¡an¡¡oven¡¡to¡¡a¡¡certain¡¡temperature¡¡to¡¡bake¡¡¡¡
something¡£¡¡The¡¡simplest¡¡way¡¡to¡¡preheat¡¡the¡¡oven¡¡is¡¡to¡¡monitor¡¡the¡¡temperature¡¡and¡¡create¡¡a¡¡¡¡
property¡¡Temperature£»¡¡like¡¡this£º¡¡
Class¡¡Oven¡¡
¡¡¡¡¡¡¡¡Private¡¡_temperature¡¡As¡¡Integer¡¡
¡¡¡¡¡¡¡¡Public¡¡Property¡¡Temperature£¨£©¡¡As¡¡Integer¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_temperature¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Set£¨ByVal¡¡Value¡¡As¡¡Integer£©¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_temperature¡¡=¡¡Value¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Set¡¡
¡¡¡¡¡¡¡¡End¡¡Property¡¡
End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡class¡¡Oven¡¡exposes¡¡its¡¡temperature¡¡as¡¡a¡¡property£»¡¡which¡¡is¡¡a¡¡direct¡¡reference¡¡to¡¡the¡¡vari
able¡¡_temperature¡£¡¡The¡¡caller¡¡of¡¡Oven¡¡would¡¡periodically¡¡ask¡¡the¡¡oven¡¡for¡¡its¡¡temperature¡¡and¡¡¡¡
decide¡¡when¡¡the¡¡oven¡¡has¡¡been¡¡preheated¡£¡¡
¡¡¡¡¡¡¡¡¡¡So£»¡¡is¡¡Oven¡¡in¡¡its¡¡current¡¡implementation¡¡actually¡¡a¡¡structural¡¡class£¿¡¡The¡¡user¡¡of¡¡Oven¡¡has¡¡¡¡
quite¡¡a¡¡bit¡¡of¡¡responsibility¡¡in¡¡that¡¡it¡¡must¡¡periodically¡¡query¡¡the¡¡temperature¡¡and¡¡decide¡¡if¡¡the¡¡¡¡
oven¡¡is¡¡preheated¡£¡¡A¡¡better¡¡implementation¡¡is¡¡to¡¡define¡¡a¡¡class¡¡that¡¡takes¡¡care¡¡of¡¡itself¡£¡¡The¡¡caller¡¡¡¡
would¡¡then¡¡just¡¡need¡¡to¡¡ask£»¡¡¡°Are¡¡you¡¡ready£¿¡±¡¡Here¡¯s¡¡how¡¡that¡¡code¡¡would¡¡look£º¡¡
Class¡¡Oven¡¡
¡¡¡¡¡¡¡¡Private¡¡_temperature¡¡As¡¡Integer¡¡
¡¡¡¡¡¡¡¡Public¡¡Sub¡¡SetTemperature£¨ByVal¡¡temperature¡¡As¡¡Integer£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_temperature¡¡=¡¡temperature¡¡
¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡Public¡¡Function¡¡AreYouPreheated£¨£©¡¡As¡¡Boolean¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Check¡¡if¡¡oven¡¡temperature¡¡matches¡¡prescribed¡¡temperature¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡False¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡166¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
144¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡mod