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

µÚ62ÕÂ

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ62ÕÂ

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

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




¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡print¡¡that¡¡forces¡¡the¡¡implementation¡¡to¡¡take¡¡a¡¡certain¡¡shape¡£¡¡Ideas¡¡when¡¡coded¡¡are¡¡Visual¡¡Basic¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interfaces£»¡¡which¡¡cannot¡¡be¡¡executed¡¡by¡¡themselves¡£¡¡From¡¡a¡¡programmatic¡¡point¡¡of¡¡view£»¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡¡is¡¡like¡¡a¡¡MustInherit¡¡base¡¡class¡¡in¡¡that¡¡you¡¡can¡¡reference¡¡an¡¡interface£»¡¡but¡¡you¡¡cannot¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡instantiate¡¡an¡¡interface¡£¡¡To¡¡get¡¡a¡¡working¡¡idea£»¡¡you¡¡write¡¡an¡¡implementation£»¡¡or¡¡implement¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡is¡¡an¡¡example¡¡of¡¡a¡¡Visual¡¡Basic¡¡interface¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Interface¡¡IExample¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡keyword¡¡Interface¡¡is¡¡associated¡¡with¡¡an¡¡identifier¡¡¡¡IExample£»¡¡and¡¡from¡¡a¡¡syntax¡¡perspec

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tive¡¡is¡¡used¡¡like¡¡the¡¡Class¡¡keyword¡£¡¡You¡¡can¡¡associate¡¡the¡¡public¡¡scope¡¡with¡¡an¡¡interface¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡¡contains¡¡methods¡¡and¡¡properties¡¡that¡¡determine¡¡the¡¡behavior¡¡of¡¡the¡¡classes¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implement¡¡the¡¡interface¡£¡¡Consider¡¡the¡¡following¡¡source¡¡code£»¡¡which¡¡defines¡¡an¡¡interface¡¡with¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡single¡¡method¡¡and¡¡single¡¡property¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Interface¡¡IExample¡¡¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Property¡¡ExampleProperty¡¡As¡¡Integer¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡you¡¡define¡¡an¡¡interface£»¡¡the¡¡included¡¡methods¡¡and¡¡properties¡¡do¡¡not¡¡have¡¡an¡¡imple

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mentation¡¡because¡¡you¡¡are¡¡defining¡¡a¡¡signature¡£¡¡A¡¡class¡¡that¡¡implements¡¡an¡¡interface¡¡will¡¡play¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡game¡¡called¡¡¡°match¡¡the¡¡properties¡¡and¡¡method¡¡signatures¡£¡±¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡Generally¡¡speaking£»¡¡the¡¡naming¡¡convention¡¡used¡¡to¡¡define¡¡a¡¡type¡¡is¡¡verbose¡¡and¡¡self¡­explanatory¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡I¡¡define¡¡interfaces£»¡¡I¡¡use¡¡identifiers¡¡prefixed¡¡with¡¡a¡¡capital¡¡I£»¡¡like¡¡IExample¡£¡¡The¡¡capital¡¡I¡¡is¡¡a¡¡mon¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡convention¡¡used¡¡to¡¡identify¡¡interfaces¡£¡¡You¡¡should¡¡use¡¡this¡¡notation¡¡to¡¡be¡¡consistent¡¡with¡¡other¡¡¡¡code¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡code¡¡is¡¡a¡¡rudimentary¡¡implementation¡¡of¡¡the¡¡defined¡¡interface¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡189¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



Class¡¡ExampleImplementation¡¡¡¡

¡¡¡¡¡¡¡¡Implements¡¡IExample¡¡



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

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



¡¡¡¡¡¡¡¡Public¡¡Property¡¡ExampleProperty£¨£©¡¡As¡¡Integer¡¡Implements¡¡IExample¡£ExampleProperty¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡0¡¡

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

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

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

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

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡ExampleImplementation¡¡implements¡¡the¡¡interface¡¡IExample¡¡using¡¡an¡¡explicit¡¡cross¡­reference¡¡¡¡

of¡¡the¡¡method¡¡or¡¡property¡¡signature¡£¡¡The¡¡cross¡­reference¡¡of¡¡interface¡¡to¡¡implementation¡¡in¡¡the¡¡¡¡

sample¡¡method¡¡is¡¡prefixed¡¡with¡¡the¡¡keyword¡¡Implements£»¡¡and¡¡the¡¡appropriate¡¡interface¡¡and¡¡¡¡

method¡£¡¡The¡¡method¡¡name¡¡doesn¡¯t¡¡need¡¡to¡¡be¡¡the¡¡same¡¡as¡¡the¡¡interface¡¯s¡¡method¡¡name¡£¡¡All¡¡¡¡

that¡¡matters¡¡is¡¡the¡¡signature¡¡of¡¡the¡¡method£»¡¡or¡¡property¡£¡¡¡¡



¡öNote¡¡¡¡Visual¡¡Basic¡¡and¡¡the¡¡CLR¡¡are¡¡single¡­inheritance¡¡models¡¡in¡¡that¡¡a¡¡class¡¡can¡¡subclass¡¡only¡¡a¡¡single¡¡class¡£¡¡¡¡

But¡¡a¡¡Visual¡¡Basic¡¡class¡¡can¡¡implement¡¡as¡¡many¡¡interfaces¡¡as¡¡necessary¡£¡¡If¡¡a¡¡class¡¡subclasses¡¡another¡¡class£»¡¡it¡¡uses¡¡¡¡

Inherits£»¡¡if¡¡it¡¡implements¡¡interfaces£»¡¡it¡¡uses¡¡Implements¡£¡¡The¡¡class¡¡is¡¡the¡¡first¡¡identifier¡¡after¡¡the¡¡colon¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡When¡¡implementing¡¡an¡¡interface£»¡¡all¡¡of¡¡the¡¡methods¡¡and¡¡properties¡¡of¡¡the¡¡interface¡¡must¡¡be¡¡¡¡

implemented¡¡in¡¡the¡¡class¡£¡¡If¡¡they¡¡are¡¡not£»¡¡then¡¡when¡¡the¡¡source¡¡code¡¡is¡¡piled£»¡¡the¡¡piler¡¡will¡¡¡¡

plain¡¡about¡¡missing¡¡methods¡¡or¡¡properties¡¡and¡¡consider¡¡the¡¡implementation¡¡as¡¡inplete¡£¡¡

¡¡¡¡¡¡¡¡¡¡As¡¡inheritance¡¡is¡¡used£»¡¡you¡¡can¡¡think¡¡of¡¡¡¡IExample¡¡as¡¡a¡¡base¡¡class¡¡that¡¡has¡¡no¡¡implementa

tion¡£¡¡The¡¡following¡¡code¡¡illustrates¡¡how¡¡to¡¡instantiate¡¡the¡¡implementation¡¡and¡¡assign¡¡the¡¡¡¡

instance¡¡to¡¡a¡¡variable¡¡that¡¡has¡¡the¡¡interface¡¡as¡¡its¡¡type¡£¡¡



Dim¡¡cls¡¡As¡¡IExample¡¡=¡¡New¡¡ExampleImplementation£¨£©¡¡

cls¡£Method£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡the¡¡class¡¡ExampleImplementation¡¡is¡¡instantiated¡¡and¡¡assigned¡¡to¡¡a¡¡variable¡¡¡¡

cls¡¡of¡¡type¡¡¡¡IExample¡£¡¡Think¡¡of¡¡it¡¡as¡¡saying£»¡¡¡°I¡¡am¡¡instantiating¡¡ExampleImplementation¡¡and¡¡¡¡

assigning¡¡the¡¡instance¡¡to¡¡the¡¡type¡¡IExample¡¡that¡¡is¡¡in¡¡my¡¡inheritance¡¡hierarchy¡£¡±¡¡When¡¡the¡¡¡¡

method¡¡cls¡£Method£¨£©¡¡is¡¡called£»¡¡the¡¡caller¡¡is¡¡really¡¡calling¡¡¡¡ExampleImplementation¡£Method£¨£©£»¡¡¡¡

although¡¡the¡¡caller¡¡would¡¡not¡¡know¡¡that£»¡¡as¡¡it¡¡is¡¡using¡¡the¡¡base¡¡type¡¡IExample¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡mechanics¡¡of¡¡defining¡¡an¡¡interface¡¡and¡¡its¡¡associated¡¡implementation¡¡are¡¡straightfor

ward£»¡¡but¡¡why¡¡would¡¡you¡¡do¡¡it£¿¡¡To¡¡explain£»¡¡I¡¯ll¡¡use¡¡a¡¡real¡­life¡¡analogy¡£¡¡

¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡say¡¡that¡¡you¡¡are¡¡going¡¡to¡¡a¡¡restaurant¡¡for¡¡an¡¡evening¡¡of¡¡fine¡¡dining¡£¡¡When¡¡you¡¡are¡¡¡¡

sitting¡¡at¡¡the¡¡table£»¡¡you¡¡expect¡¡a¡¡waiter¡¡to¡¡take¡¡your¡¡order£»¡¡serve¡¡your¡¡food£»¡¡remove¡¡the¡¡used¡¡¡¡

dishes£»¡¡and¡¡give¡¡you¡¡the¡¡bill¡£¡¡All¡¡of¡¡these¡¡actions¡¡are¡¡ideas¡¡used¡¡to¡¡run¡¡a¡¡restaurant¡¡that¡¡serves¡¡a¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡190¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡clientele¡£¡¡You¡¡make¡¡use¡¡of¡¡the¡¡idea£»¡¡as¡¡do¡¡millions¡¡of¡¡other¡¡clients¡£¡¡The¡¡idea¡¡is¡¡applied¡¡across¡¡all¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡restaurants¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Think¡¡about¡¡this¡¡a¡¡bit¡£¡¡The¡¡idea¡¡is¡¡a¡¡waiter£»¡¡but¡¡the¡¡implementation¡¡is¡¡a¡¡human¡£¡¡When¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡sit¡¡down£»¡¡your¡¡waiter¡¡may¡¡introduce¡¡himself¡¡by¡¡his¡¡name£»¡¡but¡¡do¡¡you¡¡ever¡¡use¡¡the¡¡name£¿¡¡Most¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡people¡¡don¡¯t£»¡¡because¡¡they¡¡think¡¡of¡¡the¡¡waiter¡¡as¡¡a¡¡human¡¡that¡¡takes¡¡their¡¡order£»¡¡serves¡¡their¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡food£»¡¡and¡¡so¡¡on¡£¡¡The¡¡point¡¡is¡¡that¡¡the¡¡human¡¡is¡¡the¡¡implementation£»¡¡but¡¡you¡¡really¡¡only¡¡care¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡about¡¡a¡¡waiter¡¡fulfilling¡¡the¡¡scope¡¡of¡¡the¡¡task¡£¡¡For¡¡example£»¡¡while¡¡you¡¡might¡¡be¡¡sympathetic¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡your¡¡waiter¡¡is¡¡having¡¡a¡¡bad¡¡day£»¡¡you¡¡want¡¡him¡¡to¡¡be¡¡chipper¡¡and¡¡happy£»¡¡and¡¡to¡¡do¡¡his¡¡job¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡taking¡¡your¡¡order£»¡¡serving¡¡your¡¡food£»¡¡and¡¡so¡¡on¡£¡¡Bluntly¡¡put£»¡¡you¡¡probably¡¡would¡¡not¡¡care¡¡if¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡waiter¡¯s¡¡puppy¡¡had¡¡been¡¡run¡¡over¡¡by¡¡a¡¡truck¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡is¡¡exactly¡¡what¡¡interfaces¡¡and¡¡implementations¡¡are¡¡about¡£¡¡The¡¡interface¡¡defines¡¡a¡¡role¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡tasks¡¡that¡¡an¡¡implementation¡¡is¡¡supposed¡¡to¡¡implement¡£¡¡You¡¡don¡¯t¡¡care¡¡if¡¡the¡¡implementa

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tion¡¡is¡¡capable¡¡of¡¡doing¡¡more£»¡¡or¡¡if¡¡the¡¡implementation¡¡is¡¡¡°having¡¡a¡¡bad¡¡day¡£¡±¡¡All¡¡you¡¡care¡¡about¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡that¡¡the¡¡implementation¡¡does¡¡what¡¡the¡¡interface¡¡says¡¡it¡¡should¡¡do¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡What¡¡you¡¡have¡¡is¡¡a¡¡decoupling¡¡of¡¡the¡¡idea¡¡from¡¡the¡¡interface£»¡¡just¡¡like¡¡at¡¡the¡¡restaurant£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡where¡¡you¡¡don¡¯t¡¡care¡¡if¡¡Tom£»¡¡Dick£»¡¡Mary£»¡¡or¡¡Jane¡¡is¡¡your¡¡server¡£¡¡In¡¡fact£»¡¡would¡¡you¡¡care¡¡if¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡human¡¡waiter¡¡were¡¡replaced¡¡by¡¡a¡¡robot£¿¡¡Probably¡¡not£»¡¡because¡¡what¡¡you¡¡really¡¡care¡¡about¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡eating¡¡the¡¡food¡£¡¡This¡¡is¡¡an¡¡important¡¡aspect¡¡of¡¡interfaces¡¡and¡¡implementations£»¡¡in¡¡that¡¡imple

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mentations¡¡are¡¡replaceable£»¡¡and¡¡you¡¡want¡¡to¡¡be¡¡able¡¡to¡¡swap¡¡one¡¡implementation¡¡for¡¡another¡£¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ill

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

Äã¿ÉÄÜϲ»¶µÄ