ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
¸»Ê¿¿µÐ¡ËµÍø ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

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

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡you¡¡use¡¡interfaces¡¡and¡¡types¡¡that¡¡implement¡¡interfaces£»¡¡you¡¡are¡¡writing¡¡ponent

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡oriented¡¡software¡£¡¡ponents¡¡and¡¡inheritance¡¡are¡¡two¡¡different¡¡object¡­oriented¡¡techniques¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡use¡¡inheritance¡¡to¡¡implement¡¡interfaces£»¡¡but¡¡ponents¡¡serve¡¡the¡¡purpose¡¡of¡¡making¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ideas¡¡happen¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Understanding¡¡How¡¡Inheritance¡¡and¡¡ponents¡¡Work¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inheritance¡¡is¡¡the¡¡act¡¡of¡¡defining¡¡base¡¡classes¡¡with¡¡functionality¡¡that¡¡may¡¡or¡¡may¡¡not¡¡be¡¡over

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ridden¡¡or¡¡overloaded£»¡¡as¡¡explained¡¡in¡¡the¡¡previous¡¡chapter¡£¡¡ponents¡¡define¡¡subsystems¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡are¡¡put¡¡together¡¡like¡¡pieces¡¡of¡¡a¡¡puzzle¡£¡¡The¡¡idea¡¡behind¡¡ponents¡¡is¡¡to¡¡be¡¡able¡¡to¡¡asso

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ciate¡¡two¡¡interface¡¡instances¡¡and¡¡make¡¡them¡¡work¡¡with¡¡each¡¡other¡¡without¡¡knowing¡¡what¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡other¡¡does¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡get¡¡a¡¡feeling¡¡of¡¡the¡¡difference¡¡between¡¡inheritance¡¡using¡¡classes¡¡and¡¡ponents¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡use¡¡interfaces¡¡and¡¡classes£»¡¡we¡¡will¡¡look¡¡at¡¡a¡¡classic¡¡example¡¡of¡¡inheritance¡¡and¡¡how¡¡that¡¡example¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡translates¡¡to¡¡ponents¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Illustrating¡¡Inheritance¡¡Using¡¡a¡¡Shape£»¡¡Rectangle£»¡¡and¡¡Square¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡One¡¡of¡¡the¡¡most¡¡popular¡¡examples¡¡of¡¡using¡¡inheritance¡¡involves¡¡shapes¡¡and¡¡how¡¡to¡¡calculate¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡area¡¡of¡¡a¡¡shape¡£¡¡The¡¡starting¡¡point¡¡of¡¡this¡¡inheritance¡¡is¡¡a¡¡MustInherit¡¡base¡¡class¡¡that¡¡has¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡single¡¡property¡¡and¡¡method¡¡to¡¡indicate¡¡a¡¡single¡¡dimension¡¡and¡¡its¡¡associated¡¡area¡£¡¡For¡¡example£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡following¡¡would¡¡be¡¡an¡¡appropriate¡¡base¡¡class¡¡definition¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡MustInherit¡¡Class¡¡Shape¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡MustOverride¡¡Function¡¡CalculateArea£¨£©¡¡As¡¡Double¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡method¡¡CalculateArea£¨£©¡¡is¡¡used¡¡to¡¡calculate¡¡the¡¡area¡¡of¡¡the¡¡shape¡£¡¡It¡¡is¡¡declared¡¡as¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡MustOverride¡¡and¡¡must¡¡be¡¡implemented¡¡by¡¡a¡¡derived¡¡class¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡191¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡For¡¡starters£»¡¡let¡¯s¡¡define¡¡Square£»¡¡which¡¡represents¡¡the¡¡square¡¡shape¡£¡¡



Class¡¡Square¡¡¡¡

¡¡¡¡¡¡¡¡Inherits¡¡Shape¡¡



¡¡¡¡¡¡¡¡Private¡¡_width¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡Public¡¡Property¡¡Width£¨£©¡¡As¡¡Double¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_width¡¡

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

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_width¡¡=¡¡value¡¡

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

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



¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Function¡¡CalculateArea£¨£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡Width¡¡*¡¡Width¡¡

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

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡A¡¡square¡¡has¡¡only¡¡one¡¡dimension£»¡¡Width£»¡¡which¡¡represents¡¡the¡¡width¡¡of¡¡a¡¡particular¡¡shape¡£¡¡In¡¡¡¡

the¡¡case¡¡of¡¡a¡¡square£»¡¡width¡¡means¡¡one¡¡of¡¡the¡¡four¡¡sides¡£¡¡We¡¯ve¡¡implemented¡¡the¡¡CalculateArea£¨£©¡¡¡¡

method£»¡¡which¡¡calculates¡¡the¡¡surface¡¡area¡¡of¡¡the¡¡square¡¡by¡¡multiplying¡¡the¡¡Width¡¡property¡¡¡¡

by¡¡itself¡£¡¡

¡¡¡¡¡¡¡¡¡¡A¡¡rectangle¡¡is¡¡a¡¡form¡¡of¡¡square£»¡¡and¡¡therefore¡¡¡¡Rectangle¡¡derives¡¡from¡¡¡¡Square£º¡¡



Class¡¡Rectangle¡¡¡¡

¡¡¡¡¡¡¡¡Inherits¡¡Square¡¡



¡¡¡¡¡¡¡¡Private¡¡_length¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡Public¡¡Property¡¡Length£¨£©¡¡As¡¡Double¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_length¡¡

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

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_length¡¡=¡¡value¡¡

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

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



¡¡¡¡¡¡¡¡Public¡¡Overloads¡¡Function¡¡CalculateArea£¨£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡Width¡¡*¡¡Length¡¡

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

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡Rectangle¡¡cannot¡¡be¡¡described¡¡using¡¡a¡¡single¡¡dimension£»¡¡thus¡¡we¡¡need¡¡to¡¡add¡¡the¡¡property¡¡¡¡

Length¡£¡¡In¡¡the¡¡implementation¡¡of¡¡the¡¡Rectangle¡£CalculateArea£¨£©¡¡method¡¡to¡¡calculate¡¡the¡¡area£»¡¡¡¡

the¡¡length¡¡is¡¡multiplied¡¡by¡¡the¡¡width¡£¡¡

¡¡¡¡¡¡¡¡¡¡Take¡¡a¡¡good¡¡look¡¡at¡¡how¡¡CalculateArea£¨£©¡¡is¡¡declared¡£¡¡In¡¡the¡¡case¡¡of¡¡Rectangle¡£¡¡

CalculateArea£¨£©£»¡¡the¡¡Overloads¡¡keyword¡¡is¡¡used£»¡¡not¡¡Overrides¡£¡¡This¡¡is¡¡because¡¡you¡¡want¡¡to¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡192¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡enforce¡¡calculation¡¡consistency¡£¡¡Calculation¡¡consistency¡¡is¡¡when¡¡you¡¡perform¡¡a¡¡specific¡¡calcula

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tion¡¡on¡¡a¡¡type¡¡and¡¡get¡¡the¡¡answer¡¡expected¡¡of¡¡that¡¡type£»¡¡and¡¡not¡¡some¡¡other¡¡type¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡So£»¡¡say¡¡you¡¡instantiate¡¡Rectangle£»¡¡and¡¡then¡¡cast¡¡it¡¡to¡¡Square¡£¡¡When¡¡you¡¡call¡¡CalculateArea£¨£©£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡want¡¡it¡¡to¡¡calculate¡¡as¡¡if¡¡the¡¡rectangle¡¡were¡¡a¡¡square£»¡¡not¡¡a¡¡rectangle¡£¡¡Thus£»¡¡by¡¡adding¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Overloads¡¡keyword¡¡in¡¡the¡¡¡¡Rectangle¡£CalculateArea£¨£©¡¡method£»¡¡a¡¡square¡¡is¡¡calculated¡¡as¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡square£»¡¡and¡¡a¡¡rectangle¡¡is¡¡calculated¡¡as¡¡a¡¡rectangle¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡But¡¡there¡¡is¡¡a¡¡consequence¡£¡¡Let¡¯s¡¡say¡¡Rectangle¡¡is¡¡cast¡¡to¡¡Shape¡£¡¡As¡¡the¡¡inheritance¡¡is¡¡declared¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡when¡¡calling¡¡CalculateArea£¨£©£»¡¡the¡¡area¡¡of¡¡a¡¡square¡¡is¡¡calculated£»¡¡which¡¡is¡¡not¡¡correct¡£¡¡Thus¡¡it¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡would¡¡seem¡¡that¡¡using¡¡New¡¡is¡¡incorrect£»¡¡and¡¡Overrides¡¡should¡¡be¡¡used¡¡instead¡£¡¡So¡¡using¡¡Overrides¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡solves¡¡the¡¡Shape¡£CalculateArea£¨£©¡¡problem£»¡¡but¡¡when¡¡a¡¡rectangle¡¡is¡¡converted¡¡into¡¡a¡¡square£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡area¡¡represents¡¡a¡¡rectangle¡¡and¡¡not¡¡square¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡illustrate¡¡the¡¡differences£»¡¡assuming¡¡the¡¡use¡¡of¡¡Overloads£»¡¡look¡¡at¡¡the¡¡following¡¡source¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code£»¡¡which¡¡calculates¡¡the¡¡area¡¡of¡¡a¡¡Rectangle¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡cls¡¡As¡¡Rectangle¡¡=¡¡New¡¡Rectangle£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cls¡£Width¡¡=¡¡20¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cls¡£Length¡¡=¡¡30¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡area¡¡As¡¡Double¡¡=¡¡cls¡£CalculateArea£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡Rectangle¡¡is¡¡instantiated£»¡¡and¡¡the¡¡properties¡¡Width¡¡and¡¡¡¡Length¡¡are¡¡assigned¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡values¡¡of¡¡20¡¡and¡¡30£»¡¡respectively¡£¡¡When¡¡the¡¡CalculateArea£¨£©¡¡method¡¡is¡¡called£»¡¡the¡¡found¡¡area¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡assigned¡¡to¡¡the¡¡variable¡¡area¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡source¡¡code¡¡does¡¡what¡¡we¡¡expect¡£¡¡It¡¡instantiates¡¡a¡¡rectangle£»¡¡assigns¡¡the¡¡rectangle¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dimensions£»¡¡and¡¡calculates¡¡the¡¡area¡¡of¡¡the¡¡rectangle¡£¡¡But¡¡a¡¡Rectangle¡¡object¡¡can¡¡also¡¡be¡¡assigned¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡square¡¡variable¡£¡¡Consider¡¡the¡¡following¡¡modified¡¡source¡¡code£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡rectangle¡¡As¡¡Rectangle¡¡=¡¡New¡¡Rectangle£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡rectangle¡£Width¡¡=¡¡20¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡rectangle¡£Length¡¡=¡¡30¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡square¡¡As¡¡Square¡¡=¡¡rectangle¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡area¡¡As¡¡Double¡¡=¡¡square¡£CalculateArea£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Square¡¡Area¡¡is¡¡¡¨¡¡&¡¡square¡£CalculateArea£¨£©¡¡&¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨¡¡Rectangle¡¡Area¡¡is¡¡¡¨¡¡&¡¡rectangle¡£CalculateArea£¨£©£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡the¡¡variable¡¡rectangle¡¡is¡¡of¡¡type¡¡Rectangle¡£¡¡The¡¡dimensions¡¡of¡¡the¡¡rectangle¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡assigned£»¡¡and¡¡then¡¡the¡¡rectangle¡¡is¡¡converted¡¡into¡¡a¡¡square¡¡and¡¡assigned¡¡to¡¡the¡¡variable¡¡square¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡the¡¡keyword¡¡Overloads£»¡¡the¡¡area¡¡is¡¡400£»¡¡which¡¡is¡¡correct¡¡because¡¡when¡¡we¡¡ask¡¡for¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dimensions¡¡of¡¡the¡¡square£»¡¡we¡¡get¡¡a¡¡width¡¡of¡¡20¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡various¡¡techniques¡¡used¡¡in¡¡this¡¡example¡¡are¡¡explained¡¡in¡¡the¡¡remainder¡¡of¡¡this¡¡chapter¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡example¡¡illustrates¡¡that¡¡by¡¡using¡¡inheritance£»¡¡you¡¡can¡¡cast¡¡a¡¡type¡¡and¡¡get¡¡the¡¡appropriate¡¡behavior¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡But¡¡this¡¡works¡¡only¡¡if¡¡you¡¡design¡¡your¡¡inheritance¡¡hierarchy¡¡properly¡£¡¡You¡¡need¡¡to¡¡understand¡¡that¡¡behavior¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡depends¡¡on¡¡the¡¡type¡¡that¡¡you¡¡have¡¡from¡¡the¡¡inheritance¡¡tree¡£¡¡And¡¡if¡¡you¡¡are¡¡not¡¡careful£»¡¡you¡¡can¡¡get¡¡some¡¡very¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡odd¡¡side¡¡effects¡£¡¡Visual¡¡Basic¡¡allows¡¡you¡¡to¡¡explicitly¡¡define¡¡what¡¡each¡¡method¡¡does£»¡¡and¡¡you¡¡should¡¡think¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡very¡¡hard¡¡about¡¡what¡¡each¡¡method¡¡should¡¡do¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡193¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



Illustrating¡¡ponents¡¡Using¡¡a¡¡Shape£»¡¡Rectangle£»¡¡and¡¡Square¡¡



Another¡¡way¡¡to¡¡implement¡¡a¡¡shape¡¡is¡¡to¡¡use¡¡ponents¡£¡¡Using¡¡ponents¡¡means¡¡to¡¡define¡¡¡¡

an¡¡idea£»¡¡and¡¡then¡¡define¡¡an¡¡implementation¡¡of¡¡the¡¡idea¡£¡¡Designing¡¡and¡¡implementing¡¡po

nents¡¡is¡¡not¡¡similar¡¡to¡¡designing¡¡and¡¡implementing¡¡inheritance¡¡trees¡£¡¡With¡¡inheritance£»¡¡you¡¡¡¡

need¡¡to¡¡consider¡¡type¡¡casting£»¡¡base¡¡class¡¡functionality£»¡¡and¡¡how¡¡to¡¡override¡¡or¡¡overload¡¡methods¡¡or¡¡¡¡

properties¡£¡¡£¨¡¡Type¡¡casting¡¡is¡¡when¡¡you¡¡cast¡¡to¡¡a¡¡specific¡¡type¡¡with¡¡or¡¡without¡¡an¡¡explicit¡¡cast¡¡¡¡

operator¡££©¡¡With¡¡ponents£»¡¡you¡¡need¡¡to¡¡think¡¡in¡¡terms¡¡of¡¡ideas¡¡and¡¡how¡¡they¡¡would¡¡be¡¡imple

mented¡¡as¡¡interfaces¡£¡¡

¡¡¡¡¡¡¡¡¡¡Having¡¡looked¡¡at¡¡the¡¡Shape£»¡¡Rectangle£»¡¡and¡¡Square¡¡implementation£»¡¡you¡¡might¡¡define¡¡an¡¡¡¡

interface¡¡£¨named¡¡IShape£©¡¡as¡¡follows£º¡¡



Interface¡¡IShape¡¡¡¡

¡¡¡¡¡¡¡¡Function¡¡CalculateArea£¨£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡Property¡¡Width£¨£©¡¡As¡¡Double¡¡

End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡For¡¡the¡¡IShape¡¡declaration£»¡¡you¡¡might¡¡even¡¡add¡¡a¡¡¡¡Length¡¡property£»¡¡but¡¡the¡¡overall¡¡idea¡¡of¡¡¡¡

the¡¡IShape¡¡interface¡¡is¡¡wrong¡£¡¡When¡¡you¡¡think¡¡of¡¡a¡¡shape£»¡¡do¡¡you¡¡think¡¡in¡¡terms¡¡of¡¡length¡¡and¡¡¡¡

width£¿¡¡Probably¡¡not¡£¡¡Rather£»¡¡you¡¡think¡¡in¡¡terms¡¡of¡¡area£»¡¡perimeter£»¡¡and¡¡other¡¡features¡¡that¡¡are¡¡¡¡

mon¡¡to¡¡all¡¡shapes¡£¡¡Length¡¡and¡¡width¡¡are¡¡not¡¡mon¡¡to¡¡all¡¡shapes¡£¡¡A¡¡circle¡¡has¡¡a¡¡radius¡¡or¡¡¡¡

diameter£»¡¡a¡¡triangle¡¡has¡¡base¡¡width£»¡¡height£»¡¡and¡¡triangle¡¡peak¡¡offset¡£¡¡The¡¡point¡¡is¡¡that¡¡the¡¡idea¡¡¡¡

of¡¡a¡¡shape¡¡is¡¡not¡¡the¡¡idea¡¡of¡¡a¡¡rectangle¡¡or¡¡a¡¡square¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡correct¡¡way¡¡to¡¡define¡¡the¡¡ideas¡¡as¡¡interfaces¡¡would¡¡be¡¡as¡¡follows£º¡¡



Interface¡¡IShape¡¡¡¡

¡¡¡¡¡¡¡¡Function¡¡CalculateArea£¨£©¡¡As¡¡Double¡¡

End¡¡Interface¡¡



Interface¡¡ISquare¡¡¡¡

¡¡¡¡¡¡¡¡Inherits¡¡IShape¡¡

¡¡¡¡¡¡¡¡Property¡¡Width£¨£©¡¡As¡¡Double¡¡

End¡¡Interface¡¡



Interface¡¡IRectangle¡¡¡¡

¡¡¡¡¡¡¡¡Inherits¡¡IShape¡¡

¡¡¡¡¡¡¡¡Property¡¡Width£¨£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡Property¡¡Length£¨£©¡¡As¡¡Double¡¡

End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡This¡¡code¡¡contains¡¡three¡¡interfaces£º¡¡IShape£»¡¡which¡¡defines¡¡a¡¡shape£»¡¡IRectangle£»¡¡which¡¡¡¡

describes¡¡a¡¡rectangle£»¡¡and¡¡ISquare£»¡¡which¡¡describes¡¡a¡¡square¡£¡¡The¡¡IRectangle¡¡and¡¡ISquare¡¡¡¡

interfaces¡¡subclass¡¡the¡¡IShape¡¡interface£»¡¡indicating¡¡that¡¡an¡¡IRectangle¡¡is¡¡also¡¡an¡¡¡¡IShape¡£¡¡The¡¡¡¡

ISquare¡¡interface¡¡is¡¡separate¡¡from¡¡the¡¡¡¡IRectangle¡¡interface£»¡¡because¡¡the¡¡idea¡¡of¡¡a¡¡square¡¡£¨four¡¡¡¡

equal¡¡sides£©¡¡is¡¡not¡¡the¡¡same¡¡as¡¡the¡¡idea¡¡of¡¡a¡¡rectangle¡¡£¨only¡¡the¡¡parallel¡¡sides¡¡of¡¡the¡¡four¡¡sides¡¡¡¡

must¡¡be¡¡equal£©£»¡¡even¡¡though¡¡the¡¡shapes¡¡might¡¡appear¡¡similar¡¡£¨in¡¡real¡¡life£»¡¡a¡¡square¡¡is¡¡a¡¡rectangle£»¡¡¡¡

but¡¡a¡¡rectangle¡¡is¡¡not¡¡necessarily¡¡a¡¡square£©¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡This¡¡separation¡¡of¡¡the¡¡square¡¡and¡¡rectangle¡¡interface¡¡illustrates¡¡that¡¡when¡¡designing¡¡inter

faces£»¡¡you¡¡need¡¡to¡¡focus¡¡on¡¡the¡¡specific¡¡behavior¡¡of¡¡the¡¡interface¡£¡¡You¡¡don¡¯t¡¡want¡¡to¡¡focus¡¡on¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡194¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡general¡¡behavior¡£¡¡The¡¡general¡¡behavior¡¡is¡¡managed¡¡when¡¡you¡¡design¡¡the¡¡classes¡£¡¡The¡¡modeling¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡your¡¡real¡­life¡¡experiences¡¡is¡¡defined¡¡in¡¡the¡¡implementations£»¡¡as¡¡illustrated¡¡by¡¡the¡¡following¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡example¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡SquareImpl¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ISquare£»¡¡IRectangle¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡RectangleImpl¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡IRectangle¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡SquareImpl¡¡class¡¡implements¡¡the¡¡behavior¡¡of¡¡ISquare¡¡and¡¡IRectangle£»¡¡and¡¡models¡¡real¡¡life£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡where¡¡a¡¡square¡¡is¡¡also¡¡a¡¡rectangle¡£¡¡And¡¡RectangleImpl¡¡implements¡¡only¡¡the¡¡behavior¡¡IRectangle£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡illustrating¡¡that¡¡a¡¡rectangle¡¡can¡¡only¡¡be¡¡a¡¡rectangle¡¡and¡¡not¡¡a¡¡square¡£¡¡Now¡¡you¡¡cannot¡¡write¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡where¡¡the¡¡implementation¡¡produces¡¡inconsistent¡¡results¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡When¡¡defining¡¡ideas£»¡¡the¡¡resulting¡¡interfaces¡¡could¡¡be¡¡considered¡¡as¡¡behavior¡¡characteristics¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡an¡¡implementation¡¡can¡¡have¡£¡¡It¡¡is¡¡entirely¡¡possible¡¡for¡¡an¡¡implementation¡¡to¡¡have¡¡multiple¡¡behavior¡¡character

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡istics¡£¡¡For¡¡example£»¡¡this¡¡could¡¡mean¡¡that¡¡an¡¡implementation¡¡could¡¡be¡¡both¡¡a¡¡square¡¡and¡¡rectangle¡¡at¡¡the¡¡same¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡time¡£¡¡In¡¡terms¡¡of¡¡the¡¡restaurant£»¡¡waiters¡¡are¡¡humans¡¡with¡¡hobbies£»¡¡feelings£»¡¡and¡¡desires£»¡¡although¡¡you¡¡don¡¯t¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡know¡¡these¡¡other¡¡aspects£»¡¡as¡¡you¡¡see¡¡only¡¡the¡¡waiters¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡An¡¡optimization¡¡could¡¡have¡¡been¡¡the¡¡following¡¡interface¡¡inheritance¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Interface¡¡ISquare¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡IShape¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Property¡¡Width£¨£©¡¡As¡¡Double¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Interface¡¡IRectangle¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡ISquare¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Property¡¡Length£¨£©¡¡As¡¡Double¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Interface¡¡ISquare¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡IRectangle¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Interface¡¡IRectangle¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡IShape¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Property¡¡Width£¨£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Property¡¡Length£¨£©¡¡As¡¡Double¡¡

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


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡195¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡However£»¡¡this¡¡isn¡¯t¡¡a¡¡good¡¡idea£»¡¡because¡¡at¡¡the¡¡interface¡¡level£»¡¡you¡¡are¡¡implying¡¡that¡¡a¡¡square¡¡¡¡

and¡¡rectangle¡¡are¡¡related¡£¡¡They¡¡might¡¡be¡¡at¡¡the¡¡implementation¡¡level£»¡¡but¡¡they¡¡also¡¡might¡¡not¡¡¡¡

be¡£¡¡For¡¡example£»¡¡imagine¡¡you¡¡are¡¡creating¡¡a¡¡super¡¡shape¡¡that¡¡has¡¡the¡¡characteristics¡¡of¡¡a¡¡rect

angle¡¡and¡¡a¡¡triangle¡£¡¡When¡¡creating¡¡a¡¡relationship¡¡between¡¡interfaces£»¡¡you¡¡are¡¡implying¡¡that¡¡¡¡

the¡¡super¡¡shape¡¡depending¡¡on¡¡the¡¡interface¡¡inheritance¡¡used¡¡must¡¡have¡¡the¡¡characteristics¡¡of¡¡¡¡

a¡¡square£»¡¡even¡¡though¡¡it¡¡might¡¡not¡£¡¡Thus£»¡¡when¡¡using¡¡inheritance¡¡with¡¡interfaces£»¡¡IShape¡¡as¡¡a¡¡¡¡

base¡¡interface¡¡of¡¡IRectangle¡¡and¡¡ISquare¡¡is¡¡acceptable£»¡¡but¡¡a¡¡relation¡¡between¡¡¡¡IRectangle¡¡and¡¡¡¡

ISquare¡¡is¡¡not¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡Now¡¡that¡¡you¡¡have¡¡an¡¡idea¡¡of¡¡the¡¡differences¡¡between¡¡inheritance¡¡and¡¡ponents£»¡¡we¡¡¡¡

can¡¡get¡¡started¡¡with¡¡our¡¡tax¡¡application¡£¡¡As¡¡we¡¡work¡¡through¡¡the¡¡example£»¡¡you¡¯ll¡¡learn¡¡the¡¡¡¡

details¡¡of¡¡implementing¡¡interfaces¡£¡¡



Implementing¡¡a¡¡Tax¡¡Engine¡¡



So¡¡far£»¡¡we¡¯ve¡¡discussed¡¡some¡¡basic¡¡tax¡¡concepts£»¡¡the¡¡features¡¡of¡¡the¡¡tax¡¡application£»¡¡and¡¡the¡¡¡¡

theory¡¡of¡¡inheritance£»¡¡interfaces£»¡¡and¡¡ponents¡£¡¡We¡¯re¡¡ready¡¡to¡¡implement¡¡the¡¡tax¡¡engine¡£¡¡¡¡

The¡¡preferred¡¡approach¡¡is¡¡to¡¡design¡¡the¡¡core¡¡idea¡¡and¡¡then¡¡create¡¡the¡¡other¡¡pieces£»¡¡or¡¡¡¡

dependencies¡£¡¡



Defining¡¡the¡¡Interfaces¡¡



Putting¡¡everything¡¡together¡¡and¡¡starting¡¡with¡¡the¡¡tax¡¡engine£»¡¡we¡¡can¡¡create¡¡the¡¡following¡¡¡¡

interface¡¡structure¡£¡¡



Public¡¡Interface¡¡ITaxIne¡¡¡¡

¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡RealAmount£¨£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡TaxableAmount£¨£©¡¡As¡¡Double¡¡

End¡¡Interface¡¡



Public¡¡Interface¡¡ITaxDeduction¡¡¡¡

¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Amount£¨£©¡¡As¡¡Double¡¡

End¡¡Interface¡¡



Public¡¡Interface¡¡ITaxAccount¡¡¡¡

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

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

¡¡¡¡¡¡¡¡Function¡¡GetTaxRate£¨ByVal¡¡ine¡¡As¡¡Double£©¡¡As¡¡Double¡¡

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

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

End¡¡Interface¡¡



Public¡¡Interface¡¡ITaxEngine¡¡¡¡

¡¡¡¡¡¡¡¡Function¡¡CalculateTaxToPay£¨ByVal¡¡account¡¡As¡¡ITaxAccount£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡Function¡¡CreateDeduction£¨ByVal¡¡amount¡¡As¡¡Double£©¡¡As¡¡ITaxDeduction¡¡

¡¡¡¡¡¡¡¡Function¡¡CreateIne£¨ByVal¡¡amount¡¡As¡¡Double£©¡¡As¡¡ITaxIne¡¡

¡¡¡¡¡¡¡¡Function¡¡CreateTaxAccount£¨£©¡¡As¡¡ITaxAccount
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨11£© ²È£¨11£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡