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

µÚ54²¿·Ö

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

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

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



¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Interfaces¡¡are¡¡used¡¡to¡¡separate¡¡implementation¡¡from¡¡ideas¡£¡¡Interfaces¡¡change¡¡very¡¡little£»¡¡whereas¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implementations¡¡can¡¡and¡¡will¡¡change¡¡more¡¡often¡£¡¡But¡¡if¡¡an¡¡implementation¡¡behaves¡¡like¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡¡in¡¡terms¡¡of¡¡changing¡¡interface¡¡signature£»¡¡why¡¡not¡¡just¡¡expose¡¡the¡¡class¡¡itself£¿¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡answer¡¡is¡¡that¡¡sometimes¡¡you¡¡will¡¡expose¡¡the¡¡class£»¡¡and¡¡sometimes¡¡you¡¡will¡¡expose¡¡the¡¡interface¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡the¡¡tax¡¡engine£»¡¡exposing¡¡the¡¡sealed¡¡classes¡¡TaxIne¡¡and¡¡TaxDeduction¡¡would¡¡probably¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡have¡¡been¡¡fine¡£¡¡The¡¡rule¡¡of¡¡thumb¡¡is¡¡that¡¡you¡¡expose¡¡classes¡¡only¡¡when¡¡you¡¡are¡¡sure¡¡that¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡¡signatures¡¡of¡¡methods¡¡and¡¡properties¡¡will¡¡not¡¡change¡¡very¡¡often¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementing¡¡a¡¡Base¡¡Tax¡¡Account¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡¡¡ITaxAccount¡¡interface¡¡is¡¡also¡¡a¡¡candidate¡¡for¡¡base¡¡class¡¡functionality¡£¡¡The¡¡implementation¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡this¡¡interface¡¡looks¡¡like¡¡this£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡MustInherit¡¡Class¡¡BaseTaxAccount¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ITaxAccount¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_deductions£¨100£©¡¡As¡¡ITaxDeduction¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_ines£¨100£©¡¡As¡¡ITaxIne¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡AddDeduction£¨ByVal¡¡deduction¡¡As¡¡ITaxDeduction£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ITaxAccount¡£AddDeduction¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡c1¡¡As¡¡Integer¡¡=¡¡0¡¡To¡¡100¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_deductions£¨c1£©¡¡Is¡¡Nothing¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_deductions£¨c1£©¡¡=¡¡deduction¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Exit¡¡For¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡203¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡Public¡¡Sub¡¡AddIne£¨ByVal¡¡ine¡¡As¡¡ITaxIne£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ITaxAccount¡£AddIne¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡c1¡¡As¡¡Integer¡¡=¡¡0¡¡to¡¡100¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡_ines£¨c1£©¡¡Is¡¡Nothing¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_ines£¨c1£©¡¡=¡¡ine¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Exit¡¡For¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Next¡¡

¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡Deductions£¨£©¡¡As¡¡ITaxDeduction£¨£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ITaxAccount¡£Deductions¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_deductions¡¡

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

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



¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡Ine£¨£©¡¡As¡¡ITaxIne£¨£©¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ITaxAccount¡£Ine¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_ines¡¡

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

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



¡¡¡¡¡¡¡¡Public¡¡MustOverride¡¡Function¡¡GetTaxRate£¨ByVal¡¡ine¡¡As¡¡Double£©¡¡As¡¡Double¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ITaxAccount¡£GetTaxRate¡¡

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡take¡¡stock¡¡of¡¡what¡¡has¡¡been¡¡acplished¡¡and¡¡decide¡¡if¡¡the¡¡tax¡¡engine¡¡is¡¡plete¡¡¡¡

from¡¡a¡¡base¡¡functionality¡¡perspective¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡Ideas¡¡have¡¡been¡¡defined¡¡for¡¡a¡¡plete¡¡tax¡¡engine¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡Some¡¡interfaces¡¡have¡¡been¡¡implemented¡¡in¡¡the¡¡form¡¡of¡¡base¡¡classes¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡Some¡¡interfaces¡¡have¡¡been¡¡implemented¡¡as¡¡sealed¡¡default¡¡implementations¡£¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡tax¡¡engine¡¡can¡¡be¡¡considered¡¡plete¡¡because¡¡all¡¡of¡¡the¡¡interfaces¡¡have¡¡been¡¡defined¡¡¡¡

and¡¡accounted¡¡for¡¡from¡¡a¡¡base¡¡functionality¡¡perspective¡¡as¡¡either¡¡base¡¡classes¡¡or¡¡default¡¡imple

mentations¡£¡¡It¡¡is¡¡does¡¡not¡¡mean¡¡that¡¡interfaces¡¡will¡¡always¡¡be¡¡implemented¡£¡¡Sometimes¡¡some¡¡¡¡

interfaces¡¡will¡¡not¡¡have¡¡a¡¡base¡¡functionality¡¡or¡¡base¡¡classes¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡important¡¡aspect¡¡to¡¡remember¡¡when¡¡defining¡¡the¡¡base¡¡functionality¡¡is¡¡to¡¡account¡¡for¡¡¡¡

all¡¡interfaces¡¡to¡¡serve¡¡a¡¡purpose¡£¡¡Do¡¡not¡¡define¡¡an¡¡interface¡¡as¡¡a¡¡placeholder¡¡for¡¡potential¡¡future¡¡¡¡

functionality¡£¡¡When¡¡seeing¡¡an¡¡interface£»¡¡a¡¡user¡¡expects¡¡it¡¡to¡¡serve¡¡some¡¡type¡¡of¡¡purpose¡£¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡204¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡rule¡¡of¡¡thumb¡¡for¡¡interfaces¡¡is¡¡that¡¡once¡¡defined¡¡and¡¡put¡¡into¡¡production£»¡¡they¡¡are¡¡not¡¡changed¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡rule¡¡of¡¡thumb¡¡is¡¡almost¡¡written¡¡in¡¡concrete¡£¡¡You¡¡never¡¡change¡¡interfaces¡¡once¡¡they¡¡are¡¡in¡¡production¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡because¡¡doing¡¡so¡¡would¡¡wreak¡¡havoc¡ªall¡¡the¡¡code¡¡that¡¡uses¡¡the¡¡interface¡¡would¡¡need¡¡to¡¡be¡¡updated¡£¡¡In¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡general£»¡¡if¡¡you¡¡feel¡¡the¡¡need¡¡to¡¡change¡¡an¡¡interface£»¡¡create¡¡a¡¡new¡¡one¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡With¡¡base¡¡functionality¡¡plete£»¡¡we¡¡are¡¡ready¡¡to¡¡implement¡¡a¡¡tax¡¡system¡¡for¡¡a¡¡particular¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡country¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡the¡¡Base¡¡Functionality¡¡of¡¡the¡¡Tax¡¡Engine¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡Calculate¡¡Taxes¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡We¡¡will¡¡use¡¡the¡¡base¡¡functionality¡¡of¡¡the¡¡tax¡¡engine¡¡to¡¡calculate¡¡Canadian¡¡taxes¡£¡¡I¡¡chose¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Canadian¡¡tax¡¡system¡¡because¡¡that¡¡is¡¡the¡¡system¡¡that¡¡I¡¡happen¡¡to¡¡know¡¡and¡¡understand£»¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡there¡¡is¡¡plenty¡¡of¡¡online¡¡documentation¡¡on¡¡how¡¡to¡¡calculate¡¡the¡¡tax¡¡rate¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡SOME¡¡BACKGROUND¡¡ON¡¡CANADIAN¡¡TAXES¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡first¡¡thing¡¡I¡¡would¡¡like¡¡to¡¡say¡¡about¡¡Canadian¡¡taxes¡¡is¡¡that¡¡Canadians¡¡pay¡¡too¡¡much¡ªway¡¡too¡¡much¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡second¡¡ment¡¡is¡¡that¡¡Canadian¡¡taxes¡¡are¡¡simple£»¡¡in¡¡that¡¡they¡¡don¡¯t¡¡let¡¡you¡¡write¡¡off¡¡many¡¡deductions¡¡£¨for¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡example£»¡¡interest¡¡payments¡¡on¡¡your¡¡house£©£»¡¡which¡¡brings¡¡us¡¡back¡¡to¡¡the¡¡first¡¡point¡¡that¡¡Canadians¡¡pay¡¡way¡¡too¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡much¡£¡¡Of¡¡course£»¡¡people¡¡in¡¡other¡¡countries¡¡would¡¡probably¡¡say¡¡the¡¡exact¡¡same¡¡thing¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Canadian¡¡taxes¡¡are¡¡based¡¡on¡¡calculating¡¡the¡¡tax¡¡rate¡¡at¡¡the¡¡federal¡¡level¡¡and¡¡at¡¡the¡¡provincial¡¡level¡£¡¡Thus£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡calculate¡¡your¡¡taxes£»¡¡you¡¡need¡¡to¡¡know¡¡in¡¡which¡¡province¡¡and¡¡in¡¡which¡¡year¡¡you¡¡are¡¡paying¡¡your¡¡taxes¡£¡¡Canadian¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡taxes¡¡change¡¡quite¡¡a¡¡bit¡¡depending¡¡on¡¡the¡¡year¡£¡¡From¡¡an¡¡implementation¡¡perspective£»¡¡it¡¡means¡¡the¡¡tax¡¡engine¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡must¡¡know¡¡about¡¡provincial¡¡taxes£»¡¡federal¡¡taxes£»¡¡and¡¡which¡¡year¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Capital¡¡gains¡¡in¡¡Canada¡¡are¡¡calculated¡¡on¡¡a¡¡50£¥¡¡basis¡£¡¡This¡¡means¡¡if¡¡I¡¡made¡¡a¡¡capital¡¡gain¡¡of¡¡200¡¡Canadian¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dollars£»¡¡then¡¡only¡¡100¡¡Canadian¡¡dollars¡¡are¡¡declared¡¡as¡¡taxable¡¡monies¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementing¡¡a¡¡Tax¡¡Engine¡¡and¡¡Tax¡¡Account¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementing¡¡a¡¡Canadian¡¡tax¡¡engine¡¡means¡¡deriving¡¡a¡¡class¡¡from¡¡BaseTaxEngine£»¡¡and¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡means¡¡implementing¡¡the¡¡CreateTaxAccount£¨£©¡¡method¡£¡¡The¡¡implementation¡¡of¡¡the¡¡Canadian¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tax¡¡engine¡¡will¡¡be¡¡in¡¡a¡¡new¡¡namespace£»¡¡and¡¡a¡¡good¡¡name¡¡would¡¡be¡¡Canada¡¡£¨as¡¡this¡¡is¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡LibTax¡¡project£»¡¡it¡¡will¡¡have¡¡a¡¡root¡¡namespace¡¡of¡¡LibTax£»¡¡so¡¡LibTax¡£Canada¡¡is¡¡the¡¡full¡¡namespace£©¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡code¡¡will¡¡not¡¡show¡¡the¡¡namespace¡¡details£»¡¡as¡¡they¡¡are¡¡implied¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡implementation¡¡is¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Friend¡¡Class¡¡TaxEngine¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡BaseTaxEngine¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡CreateTaxAccount£¨£©¡¡As¡¡ITaxAccount¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡TaxAccount£¨£©¡¡

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


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡205¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡implementation¡¡of¡¡the¡¡CreateTaxAccount£¨£©¡¡method£»¡¡the¡¡TaxAccount¡¡class¡¡is¡¡instan

tiated¡£¡¡TaxAccount¡¡is¡¡a¡¡class¡¡that¡¡derives¡¡from¡¡BaseTaxAccount¡¡and¡¡thus¡¡implements¡¡the¡¡ITaxAccount¡¡¡¡

interface¡£¡¡The¡¡implementation¡¡of¡¡TaxAccount¡¡is¡¡as¡¡follows£º¡¡



Friend¡¡Class¡¡TaxAccount¡¡

¡¡¡¡¡¡¡¡Inherits¡¡BaseTaxAccount¡¡



¡¡¡¡¡¡¡¡Private¡¡_province¡¡As¡¡Province¡¡

¡¡¡¡¡¡¡¡Private¡¡_year¡¡As¡¡Integer¡¡



¡¡¡¡¡¡¡¡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¡¡purpose¡¡of¡¡the¡¡GetTaxRate£¨£©¡¡method¡¡is¡¡to¡¡return¡¡the¡¡applicable¡¡tax¡¡rate¡¡for¡¡the¡¡given¡¡¡¡

amount¡£¡¡In¡¡Canada£»¡¡the¡¡tax¡¡rate¡¡is¡¡determined¡¡by¡¡which¡¡province¡¡you¡¡live¡¡in¡¡and¡¡the¡¡year¡£¡¡The¡¡¡¡

calculation¡¡in¡¡GetTaxRate£¨£©¡¡has¡¡the¡¡ability¡¡to¡¡calculate¡¡the¡¡taxes¡¡for¡¡the¡¡year¡¡2008¡¡in¡¡the¡¡Ontario¡¡¡¡

province¡£¡¡Here¡¯s¡¡the¡¡skeleton¡¡of¡¡the¡¡OntarioTax2008¡¡class£º¡¡



Public¡¡Class¡¡OntarioTax2008¡¡

¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡TaxRate£¨ByVal¡¡ine¡¡As¡¡Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Return¡¡the¡¡appropriate¡¡rate¡¡

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

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡Yet¡¡there¡¡is¡¡a¡¡problem£»¡¡and¡¡it¡¡involves¡¡the¡¡data¡¡members¡¡_province¡¡and¡¡_year¡£¡¡The¡¡data¡¡¡¡

members¡¡are¡¡used¡¡in¡¡the¡¡calculation¡¡GetTaxRate£¨£©£»¡¡but¡¡they¡¡are¡¡not¡¡assigned¡£¡¡This¡¡is¡¡a¡¡problem¡£¡¡



Assigning¡¡State¡¡When¡¡the¡¡Interface¡¡Cannot¡¡



The¡¡problem¡¡of¡¡the¡¡Canadian¡¡tax¡¡account¡¡is¡¡a¡¡mon¡¡one¡¡that¡¡you¡¡will¡¡encounter¡¡in¡¡many¡¡¡¡

situations¡£¡¡The¡¡essence¡¡of¡¡the¡¡problem¡¡is¡¡the¡¡need¡¡to¡¡assign¡¡state¡¡that¡¡is¡¡specific¡¡to¡¡an¡¡imple

mentation¡¡without¡¡violating¡¡the¡¡intention¡¡of¡¡the¡¡general¡¡interface¡£¡¡

¡¡¡¡¡¡¡¡¡¡To¡¡illustrate¡¡the¡¡problem£»¡¡let¡¯s¡¡say¡¡that¡¡the¡¡method¡¡GetTaxRate£¨£©¡¡will¡¡include¡¡a¡¡reference¡¡¡¡

to¡¡the¡¡province¡¡and¡¡year¡£¡¡The¡¡rewritten¡¡¡¡ITaxAccount¡¡interface¡¡would¡¡be¡¡as¡¡follows£º¡¡



Public¡¡Interface¡¡ITaxAccount¡¡¡¡

¡¡¡¡¡¡¡¡Sub¡¡AddDeduction£¨ByVal¡¡deduction¡¡As¡¡ITaxDeduction£©¡¡

¡¡¡¡¡¡¡¡Sub¡¡AddIne£¨ByVal¡¡ine¡¡As¡¡ITaxIne£©¡¡

¡¡¡¡¡¡¡¡Function¡¡GetTaxRate£¨ByVal¡¡ine¡¡As¡¡Double£»¡¡ByVal¡¡province¡¡As¡¡Province£»¡¡_¡¡

¡¡¡¡¡¡¡¡ByVal¡¡year¡¡As¡¡Integer£©¡¡As¡¡Double¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡206¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Deductions£¨£©¡¡As¡¡ITaxDeduction£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Ine£¨£©¡¡As¡¡ITaxIne£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡bolded¡¡code¡¡illustrates¡¡the¡¡added¡¡parameters¡¡that¡¡are¡¡used¡¡to¡¡calculate¡¡Canadian¡¡taxes¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡But¡¡is¡¡this¡¡a¡¡good¡¡solution£¿¡¡No£»¡¡it¡¯s¡¡a¡¡particularly¡¡bad¡¡solution¡£¡¡The¡¡parameters¡¡are¡¡specific¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡an¡¡implementation£»¡¡and¡¡particularly¡¡to¡¡a¡¡Canadian¡¡implementation¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡parameter¡¡year¡¡could¡¡be¡¡justified¡¡because¡¡most¡¡countries¡¡do¡¡have¡¡specific¡¡tax¡¡rates¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡implementati

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

Äã¿ÉÄÜϲ»¶µÄ