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

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tation¡¡in¡¡the¡¡base¡¡class¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Scenario¡¡3£º¡¡Implementing¡¡an¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Interface¡¡IInterface¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡Method£¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Implementation¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡IInterface¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Method£¨£©¡¡Implements¡¡IInterface¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Implementation¡£Method¡¨£©¡¡

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Module¡¡Test¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Run£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡implementation¡¡As¡¡Implementation¡¡=¡¡New¡¡Implementation£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡inst¡¡As¡¡IInterface¡¡=¡¡implementation¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Implementation¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implementation¡£Method£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Implementation¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡inst¡£Method£¨£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Module¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡Keywords¡¡used£º¡¡none¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡The¡¡class¡¡that¡¡implements¡¡the¡¡interface¡¡has¡¡a¡¡behavior£»¡¡like¡¡when¡¡a¡¡class¡¡subclasses¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implements¡¡a¡¡MustOverride¡¡method¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡Whether¡¡the¡¡variable¡¡is¡¡an¡¡interface¡¡type¡¡or¡¡an¡¡implementation¡¡type£»¡¡the¡¡method¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementation¡£Method£¨£©¡¡is¡¡called¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡213¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



Scenario¡¡4£º¡¡Implementing¡¡Two¡¡Interfaces¡¡with¡¡Same¡¡Method/Property¡¡Name¡¡



¡¡¡¡¡¡Interface¡¡IInterface1¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡Method£¨£©¡¡

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



¡¡¡¡¡¡¡¡Interface¡¡IInterface2¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡Method£¨£©¡¡

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



¡¡¡¡¡¡¡¡Class¡¡Implementation¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡IInterface1£»¡¡IInterface2¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Method1£¨£©¡¡Implements¡¡IInterface1¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Implementation¡£IInterface1¡£Method¡¨£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡Sub¡¡Method2£¨£©¡¡Implements¡¡IInterface2¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Implementation¡£IInterface2¡£Method¡¨£©¡¡

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

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



¡¡¡¡¡¡¡¡Module¡¡Test¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Run£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡implementation¡¡As¡¡Implementation¡¡=¡¡New¡¡Implementation£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡inst1¡¡As¡¡IInterface1¡¡=¡¡implementation¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡inst2¡¡¡¡As¡¡IInterface2¡¡=¡¡implementation¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Implementation¡£Method1¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡inst1¡£Method£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Implementation¡£Method2¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡inst2¡£Method£¨£©¡¡

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

¡¡¡¡¡¡¡¡End¡¡Module¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Keywords¡¡used£º¡¡special¡¡notation¡¡for¡¡the¡¡implementation¡¡of¡¡a¡¡particular¡¡interface¡¡method¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨for¡¡example£»¡¡Implements¡¡IInterface1¡£Method¡¡and¡¡Implements¡¡IInterface2¡£Method£©¡£¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡methods¡¡that¡¡are¡¡converted¡¡to¡¡implement¡¡a¡¡particular¡¡interface¡¡can¡¡still¡¡be¡¡called¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡Method1£¨£©¡¡is¡¡declared¡¡as¡¡Public£»¡¡and¡¡thus¡¡if¡¡you¡¡have¡¡a¡¡reference¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementation£»¡¡then¡¡you¡¡can¡¡call¡¡Method1£¨£©¡£¡¡



Scenario¡¡5£º¡¡Implementing¡¡an¡¡Interface¡¡That¡¡Allows¡¡Overriding¡¡



¡¡¡¡¡¡¡¡Interface¡¡IInterface¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡Method£¨£©¡¡

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


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡214¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Implementation¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡IInterface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overridable¡¡Sub¡¡Method£¨£©¡¡Implements¡¡IInterface¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Implementation¡£Method¡¨£©¡¡

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡ImplementationDerived¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡Implementation¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Sub¡¡Method£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨ImplementationDerived¡£Method¡¨£©¡¡

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Module¡¡Test¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Run£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡implementation¡¡As¡¡ImplementationDerived¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡New¡¡ImplementationDerived£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡inst¡¡As¡¡IInterface¡¡=¡¡implementation¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡ImplementationDerived¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implementation¡£Method£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡ImplementationDerived¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡inst¡£Method£¨£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Module¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Keywords¡¡used£º¡¡Overridable¡¡and¡¡Overrides¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡By¡¡default£»¡¡when¡¡you¡¡implement¡¡an¡¡interface¡¡without¡¡using¡¡the¡¡Overridable¡¡keyword£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡are¡¡saying¡¡that¡¡the¡¡derived¡¡class¡¡can¡¡overload¡¡only¡¡the¡¡method¡£¡¡In¡¡many¡¡cases£»¡¡this¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡appropriate£»¡¡as¡¡you¡¡will¡¡want¡¡to¡¡override¡¡the¡¡method¡¡and¡¡thus¡¡will¡¡need¡¡to¡¡use¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Overridable¡¡and¡¡Overrides¡¡keywords¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡This¡¡is¡¡a¡¡mon¡¡problem£»¡¡and¡¡most¡¡beginning¡¡Visual¡¡Basic¡¡programmers¡¡are¡¡puzzled¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡by¡¡the¡¡overloading¡¡behavior¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Scenario¡¡6£º¡¡An¡¡Inheritance¡¡Tree¡¡That¡¡Overrides¡¡and¡¡Overloads¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Base¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overridable¡¡Sub¡¡Method£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Base¡£Method¡¨£©¡¡

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

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


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡215¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡Class¡¡Derived1¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡Base¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Sub¡¡Method£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Derived1¡£Method¡¨£©¡¡

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

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



¡¡¡¡¡¡¡¡Class¡¡Derived2¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡Derived1¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overloads¡¡Overridable¡¡Sub¡¡Method£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Derived2¡£Method¡¨£©¡¡

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

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



¡¡¡¡¡¡¡¡Class¡¡Derived3¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡Derived2¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Overrides¡¡Sub¡¡Method£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Derived3¡£Method¡¨£©¡¡

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

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



¡¡¡¡¡¡¡¡Module¡¡Test¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡Run£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡derivedCls¡¡As¡¡Derived3¡¡=¡¡new¡¡Derived3£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡baseCls¡¡As¡¡Base¡¡=¡¡derivedCls¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡derived2cls¡¡As¡¡Derived2¡¡=¡¡derivedCls¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Derived3¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡derivedCls¡£Method£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Derived1¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡baseCls¡£Method£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'¡¡Calls¡¡Derived3¡£Method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡derived2cls¡£Method£¨£©¡¡

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

¡¡¡¡¡¡¡¡End¡¡Module¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Keywords¡¡used£º¡¡Overridable£»¡¡Overrides£»¡¡and¡¡Overloads¡£¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡inheritance¡¡hierarchy¡¡is¡¡saying¡¡that¡¡Derived1¡£Method£¨£©¡¡overrides¡¡the¡¡behavior¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡Base¡£Method£¨£©¡£¡¡Derived2¡£Method£¨£©¡¡overloads¡¡the¡¡behavior¡¡of¡¡Derived1¡£Method£¨£©£»¡¡while¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡establishing¡¡a¡¡new¡¡overriding¡¡base¡¡method¡£¡¡Derived3¡£Method£¨£©¡¡overrides¡¡the¡¡behavior¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡Derived2¡£Method£¨£©£»¡¡and¡¡not¡¡Base¡£Method£¨£©¡¡£¨very¡¡important£©¡£¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡confronted¡¡with¡¡a¡¡plex¡¡inheritance¡¡hierarchy¡¡as¡¡illustrated¡¡by¡¡scenario¡¡6£»¡¡it¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡important¡¡that¡¡you¡¡start¡¡at¡¡the¡¡base¡¡class¡¡and¡¡work¡¡up¡¡the¡¡inheritance¡¡hierarchy¡£¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡216¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡More¡¡Type¡­Casting¡¡Details¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡chapter¡¡illustrated¡¡some¡¡type¡­casting¡¡examples¡£¡¡In¡¡Visual¡¡Basic£»¡¡you¡¡have¡¡two¡¡ways¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡cast£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡forced¡¡type¡¡cast£»¡¡which¡¡can¡¡also¡¡be¡¡used¡¡on¡¡value¡¡types¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡type¡¡cast¡¡that¡¡queries¡¡if¡¡a¡¡type¡¡cast¡¡is¡¡possible¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Consider¡¡this¡¡hierarchy£º¡¡



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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡next¡¡step¡¡is¡¡to¡¡instantiate¡¡the¡¡type¡¡Derived¡¡and¡¡cast¡¡the¡¡instance¡¡to¡¡the¡¡base¡¡type£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡derivedCls¡¡As¡¡Derived¡¡=¡¡New¡¡Derived£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡baseCls¡¡As¡¡Base¡¡=¡¡derivedCls¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡casting¡¡from¡¡a¡¡derived¡¡type¡¡to¡¡a¡¡base¡¡class¡¡type£»¡¡a¡¡type¡¡cast¡¡is¡¡not¡¡necessary¡¡and¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡can¡¡assume¡¡it¡¡is¡¡implied¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡type¡¡cast¡¡is¡¡necessary¡¡when¡¡you¡¡want¡¡to¡¡cast¡¡a¡¡base¡¡class¡¡instance¡¡to¡¡a¡¡derived¡¡class¡¡instance¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Following¡¡is¡¡the¡¡source¡¡code¡¡for¡¡a¡¡forced¡¡type¡¡cast£»¡¡assuming¡¡the¡¡inheritance¡¡hierarchy¡¡from¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡previous¡¡cast¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡backToDerived¡¡As¡¡Derived¡¡=¡¡DirectCast£¨baseCls£»¡¡Derived£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡forced¡¡cast¡¡is¡¡the¡¡use¡¡of¡¡the¡¡method¡¡DirectCase¡£¡¡The¡¡cast¡¡is¡¡forced¡¡because¡¡a¡¡conver

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡sion¡¡to¡¡the¡¡desired¡¡type¡¡will¡¡occur£»¡¡regardless¡¡if¡¡it¡¡is¡¡possible¡¡or¡¡not¡£¡¡If¡¡the¡¡cast¡¡is¡¡not¡¡possible£»¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cast¡¡exception¡¡is¡¡thrown¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Another¡¡way¡¡to¡¡perform¡¡a¡¡type¡¡cast¡¡is¡¡to¡¡use¡¡a¡¡query¡¡cast£»¡¡as¡¡illustrated¡¡by¡¡the¡¡following¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code£»¡¡again¡¡assuming¡¡the¡¡inheritance¡¡hierarchy¡¡of¡¡this¡¡section¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡backToDerived¡¡As¡¡Derived¡¡=¡¡TryCast£¨baseCls£»¡¡Derived£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡code£»¡¡the¡¡cast¡¡involves¡¡using¡¡the¡¡TryCast¡¡method¡£¡¡This¡¡cast¡¡is¡¡a¡¡query¡¡because¡¡a¡¡cast¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡be¡¡attempted¡£¡¡If¡¡the¡¡cast¡¡is¡¡successful£»¡¡then¡¡an¡¡instance¡¡of¡¡the¡¡type¡¡is¡¡assigned¡¡to¡¡the¡¡vari

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡able¡¡backToDerived¡£¡¡If¡¡the¡¡cast¡¡is¡¡not¡¡possible£»¡¡then¡¡backToDerived¡¡is¡¡assigned¡¡a¡¡¡¡Nothing¡¡value¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡No¡¡exception¡¡is¡¡thrown¡£¡¡This¡¡casting¡¡technique¡¡is¡¡possible¡¡only¡¡for¡¡reference¡¡types¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡217¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



The¡¡Important¡¡Stuff¡¡to¡¡Remember¡¡



In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡about¡¡interfaces¡¡and¡¡implementations¡£¡¡Here¡¡are¡¡the¡¡key¡¡points¡¡¡¡

to¡¡remember£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Using¡¡interfaces¡¡is¡¡not¡¡like¡¡using¡¡inheritance¡£¡¡They¡¡are¡¡two¡¡separate¡¡designs£»¡¡even¡¡though¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interfaces¡¡will¡¡use¡¡inheritance¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Interfaces¡¡at¡¡an¡¡abstract¡¡level¡¡imply¡¡ideas¡¡of¡¡how¡¡you¡¡would¡¡like¡¡your¡¡application¡¡to¡¡work¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Ideas¡¡when¡¡implemented¡¡as¡¡interfaces¡¡should¡¡be¡¡general¡¡and¡¡applicable¡¡to¡¡multiple¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡application¡¡implementations¡¡for¡¡the¡¡domain¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Ideas¡¡are¡¡represented¡¡using¡¡Visual¡¡Basic¡¡interfaces¡£¡¡And¡¡interfaces¡¡are¡¡implemented¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡using¡¡classes¡¡or¡¡structures¡£¡¡But¡¡note¡¡that¡¡interfaces¡¡are¡¡reference¡¡types¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Factories¡¡are¡¡used¡¡to¡¡instantiate¡¡implementations¡¡and¡¡return¡¡an¡¡instance¡¡that¡¡imple

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ments¡¡an¡¡interface¡£¡¡Using¡¡a¡¡factory¡¡means¡¡that¡¡the¡¡user¡¡of¡¡an¡¡interface¡¡does¡¡not¡¡need¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡know¡¡which¡¡type¡¡of¡¡implementation¡¡object¡¡is¡¡instantiated¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Interfaces¡¡can¡¡be¡¡considered¡¡as¡¡facets¡¡that¡¡might¡¡be¡¡targeting¡¡a¡¡specific¡¡characteristic¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡an¡¡implementation¡£¡¡However£»¡¡as¡¡illustrated¡¡in¡¡the¡¡previous¡¡chapter£»¡¡interfaces¡¡do¡¡not¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡expose¡¡Friend¡¡state¡¡or¡¡the¡¡¡¡Friend¡¡workings¡¡of¡¡the¡¡implementations¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡ponents¡¡are¡¡a¡¡fundamental¡¡way¡¡of¡¡developing¡¡code¡¡and¡¡should¡¡be¡¡your¡¡primary¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡way¡¡of¡¡writing¡¡code¡£¡¡For¡¡the¡¡remainder¡¡of¡¡this¡¡book£»¡¡interfaces¡¡will¡¡be¡¡used¡¡whenever¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡possible¡£¡¡Take¡¡notice¡¡and¡¡try¡¡to¡¡understand¡¡what¡¡the¡¡idea¡¡behind¡¡the¡¡interface¡¡is¡£¡¡



Some¡¡Things¡¡for¡¡You¡¡to¡¡Do¡¡



The¡¡following¡¡are¡¡a¡¡couple¡¡things¡¡for¡¡you¡¡to¡¡do¡¡to¡¡apply¡¡what¡¡you¡¯ve¡¡learned¡¡in¡¡this¡¡chapter¡£¡¡



¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡Implement¡¡your¡¡own¡¡tax¡¡system¡¡using¡¡the¡¡predefined¡¡base¡¡classes¡£¡¡¡¡



¡öNote¡¡¡¡Because¡¡of¡¡the¡¡number¡¡of¡¡possible¡¡tax¡¡systems£»¡¡I¡¡do¡¡not¡¡provide¡¡an¡¡answer¡¡for¡¡exercise¡¡1¡£¡¡If¡¡you¡¡¡¡

want¡¡me¡¡to¡¡review¡¡your¡¡answer£»¡¡please¡¡send¡¡it¡¡to¡¡me¡¡at¡¡christianhgross@gmail¡£¡£¡¡



¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡Add¡¡functionality¡¡to¡¡the¡¡tax¡¡engine¡¯s¡¡base¡¡classes¡¡that¡¡implement¡¡the¡¡behavior¡¡of¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡minimum¡¡tax¡­free¡¡amount¡£¡¡This¡¡means¡¡if¡¡your¡¡ine¡¡is¡¡not¡¡above¡¡the¡¡minimum¡¡tax

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡free¡¡amount£»¡¡you¡¡do¡¡not¡¡pay¡¡taxes¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡218¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡219¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

C¡¡¡¡H¡¡¡¡A¡¡¡¡P¡¡¡¡T¡¡¡¡E¡¡¡¡R¡¡¡¡¡¡¡¡¡¡8¡¡



¡¡¡ö¡¡¡ö¡¡¡ö¡¡



Learning¡¡About¡¡ponent

Oriented¡¡Architecture¡¡



So¡¡far£»¡¡you¡¡have¡¡learned¡¡the¡¡essentials¡¡of¡¡Visual¡¡Basic¡£¡¡With¡¡the¡¡essentials£»¡¡you¡¡can¡¡write¡¡a¡¡¡¡

functional¡¡application¡¡that¡¡uses¡¡classes£»¡¡objects£»¡¡interfaces£»¡¡and¡¡inheritance¡£¡¡In¡¡this¡¡chapter£»¡¡¡¡

you¡¯ll¡¡learn¡¡about¡¡a¡¡Visual¡¡Basic¡¡programming¡¡technique¡¡that¡¡some¡¡developers¡¡define¡¡as¡¡structural¡£¡¡¡¡

A¡¡structural¡¡programming¡¡technique¡¡is¡¡when¡¡the¡¡code¡¡does¡¡not¡¡directly¡¡serve¡¡to¡¡solve¡¡a¡¡business¡¡¡¡

problem£»¡¡but¡¡solves¡¡a¡¡problem¡¡relating¡¡to¡¡building¡¡the¡¡application¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡Another¡¡purpose¡¡of¡¡this¡¡chapter¡¡is¡¡to¡¡give¡¡you¡¡more¡¡experience¡¡with¡¡developing¡¡ponent

oriented¡¡code¡£¡¡In¡¡particular£»¡¡you¡¯ll¡¡learn¡¡how¡¡to¡¡develop¡¡a¡¡kernel¡£¡¡Developing¡¡a¡¡kernel¡¡demon

strates¡¡the¡¡power¡¡and¡¡flexibility¡¡of¡¡the¡¡ponent¡­oriented¡¡development¡¡approach¡£¡¡You¡¡can¡¡¡¡

build¡¡a¡¡working¡¡system¡¡even¡¡though¡¡you¡¡might¡¡not¡¡know¡¡what¡¡all¡¡of¡¡the¡¡implementations¡¡are¡¡¡¡

ahead¡¡of¡¡time¡£¡¡This¡¡type¡¡of¡¡development¡¡makes¡¡it¡¡possible¡¡to¡¡modularize¡¡development£»¡¡in¡¡that¡¡¡¡

individual¡¡teams¡¡are¡¡responsible¡¡for¡¡certain¡¡interfaces¡£¡¡Then¡¡once¡¡the¡¡pieces¡¡have¡¡been¡¡imple

mented£»¡¡they¡¡are¡¡fitted¡¡together¡¡like¡¡a¡¡jigsaw¡¡puzzle¡£¡¡Of¡¡course£»¡¡interfaces¡¡and¡¡ponents¡¡do¡¡¡¡

not¡¡guarantee¡¡success£»¡¡but¡¡they¡¡do¡¡ensure¡¡one¡¡team¡¡does¡¡not¡¡need¡¡to¡¡wait¡¡for¡¡another¡¡team¡¡to¡¡¡¡

finish¡¡its¡¡code¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡To¡¡demonstrate¡¡all¡¡of¡¡these¡¡concepts£»¡¡we¡¯ll¡¡build¡¡an¡¡application¡¡that¡¡controls¡¡lighting¡¡in¡¡¡¡

buildings£»¡¡using¡¡the¡¡kernel¡¡programming¡¡approach¡£¡¡



Understanding¡¡Kernels¡¡



Imagine¡¡you¡¡are¡¡the¡¡owner¡¡of¡¡a¡¡house¡¡or¡¡mercial¡¡building£»¡¡and¡¡you¡¡want¡¡to¡¡reduce¡¡your¡¡¡¡

electricity¡¡bill¡£¡¡One¡¡way¡¡of¡¡doing¡¡that¡¡is¡¡to¡¡automate¡¡the¡¡lighting¡¡system¡¡of¡¡your¡¡building¡¡so¡¡that¡¡¡¡

lights¡¡are¡¡on¡¡when¡¡they¡¡need¡¡to¡¡be¡£¡¡What¡¡is¡¡unique¡¡about¡¡this¡¡system¡¡is¡¡that¡¡you¡¡have¡¡a¡¡controller¡¡¡¡

and¡¡the¡¡devices¡¡that¡¡are¡¡controlled¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡controller¡¡controls¡¡devices¡¡that¡¡it¡¡does¡¡not¡¡know¡¡about¡¡ahead¡¡of¡¡time£»¡¡but¡¡fulfills¡¡a¡¡¡¡

contract¡£¡¡The¡¡lighting¡¡system¡¡is¡¡a¡¡controller£»¡¡programmatically¡¡called¡¡a¡¡kernel£»¡¡because¡¡the¡¡¡¡

rooms¡¡that¡¡it¡¡controls¡¡are¡¡not¡¡known¡¡initially¡£¡¡The¡¡rooms¡¡are¡¡known¡¡when¡¡the¡¡controller¡¡is¡¡used¡¡¡¡

to¡¡manage¡¡the¡¡lighting¡¡system¡£¡¡The¡¡kernel¡¡programming¡¡approach¡¡is¡¡one¡¡where¡¡a¡¡core¡¡of¡¡func

tionality¡¡is¡¡developed¡£¡¡The¡¡core¡¡functionality¡¡by¡¡itself¡¡does¡¡not¡¡work£»¡¡because¡¡it¡¡relies¡¡on¡¡other¡¡¡¡

pieces¡¡to¡¡perform¡¡certain¡¡tasks¡£¡¡In¡¡programming¡¡terms£»¡¡this¡¡is¡¡called¡¡developing¡¡ponents¡¡¡¡

that¡¡use¡¡interfaces¡¡and¡¡implementations¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡197¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡220¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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