ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ37²¿·Ö
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡parameter¡¡year¡¡could¡¡be¡¡justified¡¡because¡¡most¡¡countries¡¡do¡¡have¡¡specific¡¡tax¡¡rates¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡implementations¡¡that¡¡are¡¡dependent¡¡on¡¡a¡¡year¡£¡¡Yet¡¡the¡¡parameter¡¡province¡¡has¡¡no¡¡justifi
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cation¡£¡¡Imagine¡¡trying¡¡to¡¡implement¡¡a¡¡British¡¡tax¡¡system¡¡and¡¡needing¡¡to¡¡specify¡¡a¡¡province£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡when¡¡Britain¡¡does¡¡not¡¡collect¡¡ine¡¡tax¡¡at¡¡a¡¡local¡¡level¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡solution¡¡might¡¡be¡¡to¡¡redefine¡¡the¡¡interface¡¡as¡¡follows£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡Specifics¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡CanadianProvince¡¡As¡¡Province¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡AmericanState¡¡As¡¡State¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡ITaxAccount¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡AddDeduction£¨ByVal¡¡deduction¡¡As¡¡ITaxDeduction£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡AddIne£¨ByVal¡¡ine¡¡As¡¡ITaxIne£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function¡¡GetTaxRate£¨ByVal¡¡ine¡¡As¡¡Double£»¡¡ByVal¡¡year¡¡As¡¡Integer£»¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡specifics¡¡As¡¡Specifics£©¡¡As¡¡Double¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Deductions£¨£©¡¡As¡¡ITaxDeduction£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Ine£¨£©¡¡As¡¡ITaxIne£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡new¡¡implementation¡¡has¡¡a¡¡specifics¡¡parameter£»¡¡which¡¡is¡¡of¡¡type¡¡¡¡Specifics¡£¡¡The¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡purpose¡¡of¡¡Specifics¡¡is¡¡to¡¡define¡¡a¡¡class¡¡that¡¡is¡¡a¡¡hodgepodge¡¡of¡¡information¡¡that¡¡is¡¡needed¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡determine¡¡the¡¡correct¡¡tax¡¡rate¡£¡¡However£»¡¡the¡¡Specifics¡¡approach¡¡is¡¡wrong£»¡¡for¡¡the¡¡following¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡reasons£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡It¡¡requires¡¡knowing¡¡the¡¡implementation£»¡¡which¡¡in¡¡the¡¡case¡¡of¡¡the¡¡interface¡¡is¡¡a¡¡bad¡¡idea¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡It¡¡is¡¡like¡¡going¡¡to¡¡a¡¡restaurant¡¡and¡¡saying¡¡you¡¡would¡¡like¡¡a¡¡waitress¡¡with¡¡blond¡¡hair¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Even¡¡if¡¡the¡¡type¡¡Specifics¡¡were¡¡acceptable£»¡¡you¡¡would¡¡be¡¡adding¡¡and¡¡removing¡¡data¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡members¡¡depending¡¡on¡¡how¡¡many¡¡tax¡¡systems¡¡you¡¡have¡¡implemented¡£¡¡That¡¡is¡¡a¡¡bad¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡idea¡¡and¡¡introduces¡¡maintenance¡¡issues¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡proposed¡¡solutions¡¡are¡¡not¡¡acceptable¡£¡¡Additionally£»¡¡there¡¡is¡¡still¡¡the¡¡problem¡¡of¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡having¡¡to¡¡figure¡¡out¡¡which¡¡tax¡¡rate¡¡to¡¡use¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementing¡¡Ideas¡¡with¡¡Specifics¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡implement¡¡a¡¡solution£»¡¡let¡¯s¡¡first¡¡start¡¡by¡¡fixing¡¡the¡¡TaxAccount¡¡class¡£¡¡The¡¡modified¡¡version¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡have¡¡some¡¡type¡¡of¡¡functionality¡¡that¡¡has¡¡data¡¡members¡¡that¡¡reference¡¡the¡¡year¡¡and¡¡prov
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ince¡£¡¡Here¡¡is¡¡the¡¡modified¡¡and¡¡correct¡¡implementation¡¡of¡¡TaxAccount£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡207¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡7¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TS¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡C¡¡L¡¡AS¡¡S¡¡¡¡H¡¡I¡¡E¡¡R¡¡AR¡¡C¡¡HI¡¡E¡¡S¡¡185¡¡
Friend¡¡Class¡¡TaxAccount¡¡¡¡
¡¡¡¡¡¡¡¡Inherits¡¡BaseTaxAccount¡¡
¡¡¡¡¡¡¡¡Private¡¡_province¡¡As¡¡Province¡¡
¡¡¡¡¡¡¡¡Private¡¡_year¡¡¡¡As¡¡Integer¡¡
¡¡¡¡¡¡¡¡Public¡¡Sub¡¡New¡¡£¨ByVal¡¡province¡¡As¡¡Province£»¡¡ByVal¡¡year¡¡As¡¡Integer£©¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_province¡¡=¡¡province¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_year¡¡=¡¡year¡¡
¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡GetTaxRate£¨ByVal¡¡ine¡¡As¡¡Double£©¡¡¡¡As¡¡Double¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_year¡¡=¡¡2008¡¡Then¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_province¡¡=¡¡Province¡£Ontario¡¡Then¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡OntarioTax2008¡£TaxRate£¨ine£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Throw¡¡New¡¡NotSupportedException£¨¡¨Year¡¡¡¨¡¡&¡¡_year¡¡&¡¡¡¨¡¡Province¡¡¡¨¡¡&¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_province¡¡&¡¡¡¨¡¡not¡¡supported¡¨£©¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡fix¡¡is¡¡to¡¡add¡¡a¡¡constructor¡¡that¡¡has¡¡province¡¡and¡¡year¡¡as¡¡parameters¡£¡¡This¡¡sort¡¡of¡¡fix¡¡is¡¡¡¡
quite¡¡mon£»¡¡in¡¡that¡¡you¡¡don¡¯t¡¡change¡¡the¡¡interfaces£»¡¡rather¡¡you¡¡change¡¡how¡¡the¡¡implemen
tations¡¡are¡¡instantiated¡£¡¡Remember¡¡that¡¡when¡¡you¡¡instantiate¡¡a¡¡specific¡¡implementation£»¡¡you¡¡¡¡
know¡¡what¡¡functionality¡¡you¡¡want£»¡¡and¡¡thus¡¡can¡¡give¡¡the¡¡additional¡¡parameters¡£¡¡Once¡¡you¡¡are¡¡¡¡
at¡¡the¡¡interface¡¡level£»¡¡you¡¡should¡¡need¡¡to¡¡use¡¡only¡¡general¡¡ideas¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Now¡¡the¡¡TaxEngine¡¡class¡¡needs¡¡to¡¡be¡¡fixed¡£¡¡TaxEngine¡¡is¡¡responsible¡¡for¡¡instantiating¡¡¡¡
TaxAccount£»¡¡and¡¡thus¡¡to¡¡instantiate¡¡a¡¡Canadian¡¡TaxAccount£»¡¡TaxEngine¡¡needs¡¡additional¡¡¡¡
parameters£»¡¡as¡¡follows£º¡¡
Friend¡¡Class¡¡TaxEngine¡¡¡¡
¡¡¡¡¡¡¡¡Inherits¡¡BaseTaxEngine¡¡
¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡CreateTaxAccount£¨£©¡¡As¡¡ITaxAccount¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡TaxAccount£¨Province¡£Ontario£»¡¡2008£©¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡implementation¡¡of¡¡CreateTaxAccount£¨£©£»¡¡the¡¡province¡¡Ontario¡¡and¡¡year¡¡2008¡¡are¡¡¡¡
assumed¡£¡¡Thus£»¡¡whenever¡¡TaxEngine¡¡is¡¡instantiated£»¡¡you¡¡need¡¡to¡¡make¡¡sure¡¡that¡¡the¡¡person¡¡is¡¡¡¡
in¡¡Ontario¡¡and¡¡paying¡¡taxes¡¡for¡¡the¡¡year¡¡2008¡£¡¡The¡¡implementation¡¡solves¡¡nothing¡¡and¡¡skirts¡¡¡¡
the¡¡issue¡¡of¡¡having¡¡to¡¡figure¡¡out¡¡how¡¡to¡¡deal¡¡with¡¡someone¡¡paying¡¡their¡¡taxes¡¡in¡¡British¡¡Columbia¡¡¡¡
and¡¡the¡¡year¡¡2009¡£¡¡
¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡look¡¡at¡¡the¡¡implementation¡¡of¡¡TaxEngine£»¡¡you¡¡will¡¡notice¡¡it¡¡is¡¡short¡£¡¡One¡¡obvious¡¡solu
tion¡¡would¡¡be¡¡to¡¡create¡¡a¡¡TaxEngine¡¡type¡¡for¡¡each¡¡province¡¡and¡¡each¡¡year¡£¡¡Here¡¡are¡¡two¡¡examples£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡208¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
186¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡7¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TS¡¡¡¡¡¡AN¡¡D¡¡¡¡C¡¡L¡¡AS¡¡S¡¡¡¡H¡¡I¡¡E¡¡R¡¡AR¡¡C¡¡H¡¡IE¡¡S¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Friend¡¡Class¡¡Ontario2008TaxEngine¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡BaseTaxEngine¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡CreateTaxAccount£¨£©¡¡As¡¡ITaxAccount¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡TaxAccount£¨Province¡£Ontario£»¡¡2008£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Friend¡¡Class¡¡BritishColumbia2009TaxEngine¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡BaseTaxEngine¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡CreateTaxAccount£¨£©¡¡As¡¡ITaxAccount¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡TaxAccount£¨Province¡£BritishColumbia£»¡¡2009£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡solution¡¡is¡¡not¡¡that¡¡bad£»¡¡because¡¡to¡¡be¡¡able¡¡to¡¡instantiate¡¡the¡¡correct¡¡tax¡¡engine£»¡¡you¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡just¡¡need¡¡to¡¡define¡¡a¡¡factory¡¡that¡¡knows¡¡which¡¡class¡¡to¡¡instantiate¡£¡¡But¡¡for¡¡the¡¡problem¡¡at¡¡hand£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡solution¡¡is¡¡extremely¡¡tedious£»¡¡as¡¡you¡¡could¡¡end¡¡up¡¡with¡¡hundreds£»¡¡if¡¡not¡¡thousands£»¡¡of¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TaxEngine¡¡definitions¡£¡¡You¡¡would¡¡use¡¡the¡¡specific¡¡implementation¡¡approach¡¡when¡¡you¡¡have¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡fewer¡¡than¡¡a¡¡dozen¡¡variations¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡better¡¡approach¡¡is¡¡to¡¡add¡¡an¡¡interface¡¡specific¡¡to¡¡the¡¡Canadian¡¡tax¡¡system¡£¡¡Think¡¡of¡¡it¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡as¡¡follows¡£¡¡When¡¡you¡¡are¡¡instantiating¡¡the¡¡tax¡¡engine£»¡¡you¡¡will¡¡need¡¡to¡¡know¡¡which¡¡tax¡¡system¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡use¡£¡¡The¡¡factory¡¡protects¡¡you¡¡from¡¡needing¡¡to¡¡know¡¡which¡¡type¡¡to¡¡instantiate£»¡¡but¡¡there¡¡is¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡nothing¡¡wrong¡¡with¡¡giving¡¡some¡¡extra¡¡information¡¡that¡¡could¡¡be¡¡used¡¡by¡¡a¡¡factory¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Thus£»¡¡the¡¡solution¡¡is¡¡to¡¡define¡¡a¡¡new¡¡interface¡¡called¡¡ICanadaTaxEngine¡£¡¡The¡¡purpose¡¡of¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ICanadaTaxEngine¡¡is¡¡to¡¡add¡¡factory¡¡methods¡¡that¡¡are¡¡used¡¡to¡¡instantiate¡¡types¡¡with¡¡parameters¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡specific¡¡to¡¡the¡¡implementation¡£¡¡Following¡¡is¡¡the¡¡definition¡¡of¡¡the¡¡ICanadaTaxEngine¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Enum¡¡Province¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Alberta¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡BritishColumbia¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Manitoba¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡NewBrunswick¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡NewfoundlandLabrador¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡NovaScotia¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Nunavut¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ontario¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡PrinceEdwardIsland¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Quebec¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Saskatchewan¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Yukon¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Enum¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡ICanadaTaxEngine¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function¡¡CreateTaxAccount£¨ByVal¡¡province¡¡As¡¡Province£»¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡year¡¡As¡¡Integer£©¡¡As¡¡ITaxAccount¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Function¡¡CreateCapitalGain£¨ByVal¡¡amount¡¡As¡¡Double£©¡¡As¡¡ITaxIne¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡209¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡7¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TS¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡C¡¡L¡¡AS¡¡S¡¡¡¡H¡¡I¡¡E¡¡R¡¡AR¡¡C¡¡HI¡¡E¡¡S¡¡187¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡definition¡¡of¡¡ICanadaTaxEngine¡¡contains¡¡two¡¡additional¡¡methods£º¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡CreateTaxAccount£¨£©¡¡is¡¡used¡¡to¡¡instantiate¡¡a¡¡tax¡¡account¡¡specific¡¡to¡¡a¡¡province¡¡and¡¡year¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡CreateCapitalGain£¨£©¡¡is¡¡used¡¡to¡¡instantiate¡¡an¡¡ine¡¡using¡¡the¡¡Canadian¡¡capital¡¡gains¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡calculation¡£¡¡
¡¡¡¡¡¡¡¡¡¡Thus£»¡¡the¡¡implementation¡¡of¡¡TaxEngine¡¡bees¡¡the¡¡following¡£¡¡
Friend¡¡Class¡¡TaxEngine¡¡
¡¡¡¡¡¡¡¡Inherits¡¡BaseTaxEngine¡¡
¡¡¡¡¡¡¡¡Implements¡¡ICanadaTaxEngine¡¡
¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡CreateTaxAccount£¨£©¡¡As¡¡ITaxAccount¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡TaxAccount£¨Province¡£Ontario£»¡¡2008£©¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡Public¡¡Overloads¡¡Function¡¡CreateTaxAccount£¨ByVal¡¡province¡¡As¡¡Province£»¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡year¡¡As¡¡Integer£©¡¡¡¡_¡¡¡¡
¡¡¡¡¡¡¡¡As¡¡ITaxAccount¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ICanadaTaxEngine¡£CreateTaxAccount¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡TaxAccount£¨province£»¡¡year£©¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡Public¡¡Function¡¡CreateCapitalGain£¨ByVal¡¡amount¡¡As¡¡Double£©¡¡As¡¡ITaxIne¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ICanadaTaxEngine¡£CreateCapitalGain¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡TaxIne£¨amount£»¡¡0¡£50£©¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡modified¡¡implementation¡¡of¡¡TaxEngine£»¡¡the¡¡class¡¡still¡¡derives¡¡from¡¡BaseTaxEngine£»¡¡¡¡
fulfilling¡¡the¡¡requirement¡¡of¡¡being¡¡a¡¡general¡¡tax¡¡engine¡£¡¡However£»¡¡for¡¡the¡¡additional¡¡require
ments¡¡of¡¡the¡¡Canadian¡¡tax¡¡system£»¡¡we¡¡implement¡¡the¡¡ICanadaTaxEngine¡¡interface¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Defining¡¡a¡¡specific¡¡interface¡¡that¡¡implies¡¡a¡¡certain¡¡implementation¡¡is¡¡fine£»¡¡because¡¡the¡¡¡¡
specific¡¡interface¡¡is¡¡not¡¡bound¡¡to¡¡a¡¡certain¡¡implementation¡£¡¡The¡¡better¡¡way¡¡to¡¡understand¡¡¡¡
this¡¡implementation¡¡technique¡¡is¡¡to¡¡consider¡¡the¡¡specific¡¡interface¡¡as¡¡a¡¡characteristic¡¡that¡¡¡¡
an¡¡implementation¡¡is¡¡capable¡¡of¡¡supporting¡£¡¡This¡¡goes¡¡back¡¡to¡¡the¡¡shape¡¡example£»¡¡where¡¡a¡¡¡¡
square¡¡can¡¡support¡¡both¡¡the¡¡ISquare¡¡and¡¡IRectangle¡¡interfaces¡£¡¡¡¡
Using¡¡the¡¡Tax¡¡Engine¡¡
The¡¡last¡¡step¡¡is¡¡to¡¡use¡¡the¡¡tax¡¡engine¡¡to¡¡calculate¡¡some¡¡taxes¡£¡¡The¡¡following¡¡is¡¡an¡¡example¡¡of¡¡¡¡
calculating¡¡the¡¡taxes¡¡for¡¡Ontario¡¡in¡¡2008¡£¡¡
Dim¡¡engine¡¡As¡¡ITaxEngine¡¡=¡¡EngineCreator¡£CreateCanadianTaxEngine£¨£©¡¡
Dim¡¡canadaEngine¡¡As¡¡ICanadaTaxEngine¡¡=¡¡TryCast£¨engine£»¡¡ICanadaTaxEngine£©¡¡
Dim¡¡account¡¡As¡¡ITaxAccount¡¡=¡¡canadaEngine¡£CreateTaxAccount£¨Province¡£Ontario£»¡¡2008£©¡¡
Dim¡¡ine¡¡As¡¡ITaxIne¡¡=¡¡engine¡£CreateIne£¨100£©¡¡
Dim¡¡capitalGain¡¡As¡¡ITaxIne¡¡=¡¡canadaEngine¡£CreateCapitalGain£¨100£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡210¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
188¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡7¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TS¡¡¡¡¡¡AN¡¡D¡¡¡¡C¡¡L¡¡AS¡¡S¡¡¡¡H¡¡I¡¡E¡¡R¡¡AR¡¡C¡¡H¡¡IE¡¡S¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡account¡£AddIne£¨ine£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡account¡£AddIne£¨capitalGain£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡deduction¡¡As¡¡ITaxDeduction¡¡=¡¡engine¡£CreateDeduction£¨20£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡account¡£AddDeduction£¨deduction£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡taxToPay¡¡As¡¡Double¡¡=¡¡engine¡£CalculateTaxToPay£¨account£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Tax¡¡to¡¡pay¡¡£¨¡¨¡¡&¡¡taxToPay¡¡&¡¡¡¨£©¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Notice¡¡the¡¡definition¡¡of¡¡the¡¡variables¡¡engine¡¡and¡¡canadaEngine¡£¡¡This¡¡is¡¡fine£»¡¡because¡¡what¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡we¡¡are¡¡doing¡¡with¡¡the¡¡interfaces¡¡is¡¡choosing¡¡a¡¡characteristic¡¡that¡¡can¡¡be¡¡dynamically¡¡queried¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Learning¡¡More¡¡About¡¡Inheritance¡¡and¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Type¡¡Casting¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡chapter¡¡introduced¡¡interfaces¡¡and¡¡ponents£»¡¡and¡¡delved¡¡deeper¡¡into¡¡inheritance¡£¡¡Here£»¡¡I¡¯ll¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡provide¡¡more¡¡details¡¡about¡¡inheritance¡¡and¡¡type¡¡casting¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡More¡¡Inheritance¡¡Details¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡this¡¡section£»¡¡I¡¡am¡¡going¡¡to¡¡clearly¡¡lay¡¡out¡¡how¡¡inheritance¡¡works¡¡in¡¡Visual¡¡Basic¡£¡¡I¡¡will¡¡present¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡examples¡¡of¡¡usage¡¡for¡¡six¡¡scenarios¡£¡¡Each¡¡example¡¡is¡¡followed¡¡by¡¡a¡¡list¡¡explaining¡¡the¡¡key¡¡points¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡understand¡£¡¡My¡¡goal¡¡is¡¡to¡¡illustrate¡¡all¡¡of¡¡the¡¡possible¡¡scenarios¡¡so¡¡that¡¡you¡¡have¡¡a¡¡reference¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡how¡¡inheritance¡¡works¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡All¡¡of¡¡the¡¡examples¡¡demonstrate¡¡using¡¡methods£»¡¡but¡¡it¡¡is¡¡possible¡¡to¡¡apply¡¡the¡¡same¡¡inheritance¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡techniques¡¡using¡¡properties¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Scenario¡¡1£º¡¡Overloading¡¡Base¡¡Class¡¡Functionality¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Base¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Method£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Base¡£Method¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Derived¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡Base¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overloads¡¡Sub¡¡Method£¨£©¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Derived¡£Method¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡211¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡7¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TS¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡C¡¡L¡¡AS¡¡S¡¡¡¡H¡¡I¡¡E¡¡R¡¡AR¡¡C¡¡HI¡¡E¡¡S¡¡189¡¡
¡¡¡¡¡¡¡¡Module¡¡Test¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Run£¨£©¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡derivedCls¡¡As¡¡Derived¡¡=¡¡New¡¡Derived£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡baseCls¡¡As¡¡Base¡¡=¡¡derivedCls¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Derived¡£Method¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡derivedCls¡£Method£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Base¡£Method¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡baseCls¡£Method£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡End¡¡Module¡¡
¡¡¡¡¡¡¡¡o¡¡¡¡Keywords¡¡used£º¡¡Overloads¡¡in¡¡the¡¡derived¡¡class¡¡to¡¡indicate¡¡the¡¡method¡¡is¡¡being¡¡overloaded¡£¡¡
¡¡¡¡¡¡¡¡o¡¡¡¡Overloading¡¡a¡¡method¡¡means¡¡to¡¡change¡¡the¡¡functionality¡¡of¡¡the¡¡method¡¡in¡¡the¡¡derived¡¡class¡£¡¡
¡¡¡¡¡¡¡¡o¡¡¡¡Which¡¡method¡¡is¡¡called¡¡in¡¡the¡¡inheritance¡¡depends¡¡on¡¡the¡¡type¡¡of¡¡the¡¡variable¡¡on¡¡which¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡method¡¡is¡¡called¡£¡¡Thus£»¡¡if¡¡the¡¡variable¡¡is¡¡of¡¡type¡¡Base£»¡¡Base¡£Method£¨£©¡¡is¡¡called£»¡¡if¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡variable¡¡is¡¡of¡¡type¡¡Derived£»¡¡Derived¡£Method£¨£©¡¡is¡¡called¡£¡¡
Scenario¡¡2£º¡¡Overriding¡¡Base¡¡Class¡¡Functionality¡¡
¡¡¡¡¡¡¡¡Class¡¡Base¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overridable¡¡Sub¡¡Method£¨£©¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Base¡£Method¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡Class¡¡Derived¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡Base¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Sub¡¡Method£¨£©¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Derived¡£Method¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡Module¡¡Test¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Run£¨£©¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡derivedCls¡¡As¡¡Derived¡¡=¡¡New¡¡Derived£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡baseCls¡¡As¡¡Base¡¡=¡¡derivedCls¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Derived¡£Method¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡derivedCls¡£Method£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Derived¡£Method¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡baseCls¡£Method£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡End¡¡Module¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡212¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
190¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡7¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TS¡¡¡¡¡¡AN¡¡D¡¡¡¡C¡¡L¡¡AS¡¡S¡¡¡¡H¡¡I¡¡E¡¡R¡¡AR¡¡C¡¡H¡¡IE¡¡S¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡Keywords¡¡used£º¡¡Overridable¡¡in¡¡the¡¡base¡¡class¡¡to¡¡indicate¡¡the¡¡method¡¡behavior¡¡can¡¡be¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡changed¡¡in¡¡the¡¡derived¡¡class¡£¡¡Overrides¡¡is¡¡used¡¡in¡¡the¡¡derived¡¡classes¡¡to¡¡indicate¡¡a¡¡method¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡the¡¡new¡¡behavior¡£¡¡Multiple¡¡levels¡¡of¡¡inheritance¡¡require¡¡multiple¡¡usages¡¡of¡¡Overrides¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡Overriding¡¡a¡¡method¡¡means¡¡to¡¡change¡¡the¡¡behavior¡¡of¡¡the¡¡method¡¡in¡¡the¡¡base¡¡class¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡of¡¡the¡¡derived¡¡class¡£¡¡If¡¡there¡¡are¡¡multiple¡¡levels¡¡of¡¡inheritance£»¡¡then¡¡the¡¡functionality¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡used¡¡is¡¡the¡¡instantiated¡¡type¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡You¡¡can¡¡also¡¡define¡¡a¡¡Overridable¡¡base¡¡class¡¡method¡¡using¡¡the¡¡MustOverride¡¡keyword¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡difference¡¡between¡¡Overridable¡¡and¡¡MustOverride¡¡is¡¡that¡¡Overridable¡¡has¡¡a¡¡method¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡property¡¡implementation¡¡in¡¡the¡¡base¡¡class£»¡¡whereas¡¡MustOverride¡¡has¡¡no¡¡implemen
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tation¡¡in¡¡the¡¡base¡¡class¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sc
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾Ñé½±Àø£¬ÈÏÕæдԴ´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾Ñé½±ÀøŶ£¡