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

µÚ58²¿·Ö

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

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

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





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


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

198¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡8¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TO¡¡R¡¡IE¡¡N¡¡T¡¡E¡¡D¡¡¡¡AR¡¡C¡¡HI¡¡TE¡¡CT¡¡U¡¡R¡¡E¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ponents¡¡are¡¡implemented¡¡at¡¡the¡¡technical¡¡level¡¡using¡¡interfaces¡¡and¡¡classes¡¡that¡¡subclass¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡interfaces¡£¡¡The¡¡interface¡¡represents¡¡an¡¡idea£»¡¡and¡¡the¡¡classes¡¡represent¡¡the¡¡implementation¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡an¡¡idea¡£¡¡A¡¡class¡¡could¡¡implement¡¡multiple¡¡interfaces£»¡¡where¡¡each¡¡interface¡¡represents¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡unique¡¡characteristic¡¡of¡¡the¡¡class¡¡implementation¡£¡¡Ideas¡¡and¡¡interfaces¡¡also¡¡represent¡¡contracts¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡standards¡£¡¡The¡¡kernel¡¡defines¡¡a¡¡standard£»¡¡and¡¡the¡¡ponent¡¡has¡¡the¡¡responsibility¡¡of¡¡imple

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡menting¡¡that¡¡standard¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implementing¡¡a¡¡kernel¡¡is¡¡like¡¡being¡¡a¡¡coach¡£¡¡A¡¡coach¡¡thinks¡¡of¡¡where¡¡to¡¡place¡¡players¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡field¡¡and¡¡develops¡¡strategies¡¡that¡¡the¡¡players¡¡need¡¡to¡¡implement¡£¡¡But¡¡on¡¡game¡¡day£»¡¡the¡¡players¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡do¡¡what¡¡they¡¡think¡¡is¡¡best£»¡¡and¡¡the¡¡coach¡¡is¡¡powerless¡£¡¡A¡¡coach¡¡can¡¡teach¡¡the¡¡players£»¡¡but¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡whether¡¡they¡¡apply¡¡that¡¡knowledge¡¡is¡¡up¡¡to¡¡the¡¡individual¡¡players¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡programming¡¡terms£»¡¡the¡¡kernel¡¡is¡¡the¡¡coach£»¡¡and¡¡the¡¡external¡¡implementations¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡manipulate¡¡are¡¡the¡¡players¡£¡¡When¡¡designing¡¡interfaces¡¡that¡¡other¡¡pieces¡¡of¡¡functionality¡¡will¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implement£»¡¡you¡¡cannot¡¡watch¡¡over¡¡the¡¡shoulders¡¡of¡¡the¡¡programmers¡¡and¡¡make¡¡sure¡¡they¡¡do¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡things¡¡correctly¡£¡¡You¡¡need¡¡to¡¡trust£»¡¡but¡¡you¡¡also¡¡need¡¡to¡¡implement¡¡a¡¡mode¡¡of¡¡programming¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡where¡¡you¡¡assume¡¡the¡¡programmers¡¡are¡¡going¡¡to¡¡do¡¡things¡¡incorrectly¡£¡¡This¡¡has¡¡nothing¡¡to¡¡do¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡the¡¡personal¡¡abilities¡¡of¡¡the¡¡other¡¡programmers¡£¡¡It¡¡has¡¡to¡¡do¡¡with¡¡the¡¡ability¡¡to¡¡make¡¡sure¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡your¡¡kernel¡¡continues¡¡functioning£»¡¡even¡¡when¡¡someone¡¡makes¡¡a¡¡mistake¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Remember¡¡that¡¡when¡¡implementing¡¡a¡¡kernel£»¡¡you¡¡are¡¡implementing¡¡a¡¡controller£»¡¡and¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡devising¡¡the¡¡strategy¡¡of¡¡the¡¡application¡£¡¡You¡¡are¡¡just¡¡not¡¡doing¡¡all¡¡of¡¡the¡¡implementations¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡you¡¡write¡¡production¡¡code£»¡¡and¡¡you¡¡have¡¡been¡¡put¡¡in¡¡charge¡¡of¡¡writing¡¡a¡¡kernel£»¡¡count¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡yourself¡¡lucky¡£¡¡But¡¡remember¡¡with¡¡the¡¡job¡¡of¡¡building¡¡a¡¡kernel¡¡es¡¡great¡¡responsibility¡£¡¡If¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡your¡¡kernel¡¡is¡¡buggy¡¡or¡¡badly¡¡designed£»¡¡then¡¡the¡¡external¡¡implementations¡¡will¡¡also¡¡be¡¡buggy¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡potentially¡¡badly¡¡designed¡£¡¡The¡¡kernel¡¡is¡¡the¡¡rock¡¡and¡¡foundation¡¡of¡¡the¡¡application¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Organizing¡¡the¡¡Lighting¡¡Application¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡the¡¡moment£»¡¡imagine¡¡we¡¡are¡¡not¡¡developing¡¡software£»¡¡but¡¡actually¡¡building¡¡a¡¡house¡£¡¡And¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡in¡¡this¡¡house£»¡¡we¡¡are¡¡going¡¡to¡¡add¡¡a¡¡central¡¡lighting¡¡system¡£¡¡The¡¡make¡¡of¡¡light¡¡bulbs£»¡¡lamps£»¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lighting¡¡controller¡¡are¡¡not¡¡identical¡£¡¡This¡¡is¡¡interesting¡¡in¡¡that¡¡multiple¡¡panies¡¡make¡¡prod

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ucts¡¡that¡¡work¡¡with¡¡each¡¡other¡¯s¡¡device£»¡¡because¡¡all¡¡panies¡¡adhere¡¡to¡¡a¡¡particular¡¡standard¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡process¡¡of¡¡standardization¡¡is¡¡all¡¡around¡¡us£»¡¡and¡¡is¡¡as¡¡simple¡¡as¡¡the¡¡electricity¡¡that¡¡es¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡out¡¡of¡¡our¡¡electrical¡¡outlets¡£¡¡However£»¡¡what¡¡is¡¡a¡¡standard¡¡in¡¡one¡¡country¡¡is¡¡not¡¡necessarily¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡standard¡¡in¡¡another¡¡country¡£¡¡Different¡¡countries¡¡will¡¡have¡¡different¡¡standard¡¡voltages¡£¡¡In¡¡terms¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡software£»¡¡the¡¡kernel¡¡represents¡¡a¡¡standard¡¡that¡¡allows¡¡the¡¡integration¡¡of¡¡ponents¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡lighting¡¡application¡¡will¡¡include¡¡these¡¡features£º¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡room¡¡where¡¡the¡¡light¡¡can¡¡be¡¡controlled¡¡using¡¡either¡¡a¡¡simple¡¡on/off¡¡switch¡¡or¡¡a¡¡gradual¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡light¡­intensity¡¡mechanism¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡controller¡¡represents¡¡a¡¡building£»¡¡and¡¡the¡¡rooms¡¡within¡¡the¡¡building¡¡can¡¡be¡¡grouped£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡making¡¡it¡¡simpler¡¡to¡¡perform¡¡group¡¡operations¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Rooms¡¡are¡¡associated¡¡with¡¡identifiers¡¡that¡¡allow¡¡each¡¡room¡¡to¡¡be¡¡isolated¡¡individually¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Rooms¡¡can¡¡be¡¡associated¡¡with¡¡a¡¡set¡¡of¡¡attributes¡¡that¡¡indicate¡¡the¡¡behavior¡¡they¡¡do¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡do¡¡not¡¡support¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡221¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡8¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡T¡¡O¡¡R¡¡IE¡¡N¡¡TE¡¡D¡¡¡¡¡¡A¡¡R¡¡CH¡¡I¡¡TE¡¡C¡¡TU¡¡R¡¡E¡¡199¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡source¡¡code¡¡will¡¡implement¡¡the¡¡controller¡¡as¡¡a¡¡library¡¡project¡¡named¡¡¡¡LibLightingSystem¡£¡¡¡¡

This¡¡library¡¡project¡¡will¡¡also¡¡define¡¡the¡¡interfaces¡¡that¡¡the¡¡ponents¡¡will¡¡implement¡£¡¡To¡¡¡¡

demonstrate¡¡building¡¡a¡¡plete¡¡working¡¡application£»¡¡two¡¡other¡¡projects¡¡implement¡¡the¡¡inter

faces¡¡and¡¡represent¡¡ponents£º¡¡Museum¡¡and¡¡Home¡£¡¡The¡¡key¡¡characteristics¡¡of¡¡a¡¡museum¡¡are¡¡that¡¡¡¡

some¡¡rooms¡¡are¡¡made¡¡dark¡¡at¡¡night¡¡and¡¡are¡¡pletely¡¡managed¡¡by¡¡the¡¡controller£»¡¡while¡¡other¡¡¡¡

rooms¡¡are¡¡controlled¡¡individually¡¡in¡¡the¡¡room¡¡itself¡¡and¡¡also¡¡can¡¡be¡¡managed¡¡by¡¡the¡¡controller¡£¡¡¡¡

The¡¡key¡¡characteristics¡¡of¡¡a¡¡home¡¡are¡¡that¡¡all¡¡of¡¡the¡¡rooms¡¡are¡¡individually¡¡controlled£»¡¡but¡¡they¡¡¡¡

have¡¡sensors¡¡that¡¡allow¡¡automatic¡¡control¡£¡¡Some¡¡of¡¡the¡¡lighting¡¡associated¡¡with¡¡the¡¡house¡¡depends¡¡¡¡

on¡¡certain¡¡prerequisites¡¡being¡¡fulfilled¡£¡¡For¡¡example£»¡¡night¡­lights¡¡might¡¡turn¡¡on¡¡depending¡¡on¡¡¡¡

the¡¡time¡¡of¡¡year£»¡¡or¡¡room¡¡lights¡¡might¡¡be¡¡turned¡¡on¡¡and¡¡off¡¡automatically¡¡when¡¡no¡¡one¡¡is¡¡home¡£¡¡¡¡

As¡¡usual£»¡¡we¡¡will¡¡use¡¡a¡¡testing¡¡console¡¡application£»¡¡named¡¡TestLightingSystem£»¡¡to¡¡test¡¡the¡¡three¡¡¡¡

assemblies¡¡£¨it¡¡is¡¡the¡¡startup¡¡project£©¡£¡¡Figure¡¡8¡­1¡¡shows¡¡the¡¡project¡¡structure¡£¡¡



Figure¡¡8¡­1¡£¡¡Lighting¡¡system¡¡application¡¡project¡¡structure¡¡



Building¡¡the¡¡Kernel¡¡



The¡¡lighting¡¡system¡¡is¡¡a¡¡two¡­part¡¡implementation¡£¡¡The¡¡first¡¡part¡¡is¡¡that¡¡we¡¡must¡¡write¡¡code¡¡that¡¡¡¡

works¡¡properly¡£¡¡The¡¡second¡¡part¡¡is¡¡to¡¡integrate¡¡code¡¡that¡¡someone¡¡else¡¡has¡¡written¡¡and¡¡make¡¡¡¡

sure¡¡that¡¡if¡¡that¡¡code¡¡does¡¡not¡¡work¡¡properly¡¡for¡¡some¡¡reason£»¡¡those¡¡problems¡¡will¡¡not¡¡affect¡¡the¡¡¡¡

code¡¡that¡¡we¡¡wrote¡£¡¡

¡¡¡¡¡¡¡¡¡¡This¡¡application¡¡is¡¡plicated¡¡by¡¡the¡¡fact¡¡that¡¡we¡¡are¡¡dealing¡¡with¡¡the¡¡unknown¡£¡¡In¡¡the¡¡¡¡

previous¡¡examples£»¡¡we¡¡had¡¡control¡¡of¡¡every¡¡class£»¡¡interface£»¡¡and¡¡definition¡£¡¡This¡¡time£»¡¡we¡¡are¡¡¡¡

not¡¡in¡¡control£»¡¡and¡¡thus¡¡we¡¡need¡¡to¡¡use¡¡a¡¡defensive¡¡style¡¡of¡¡programming¡£¡¡This¡¡means¡¡we¡¡need¡¡¡¡

to¡¡write¡¡many¡¡tests¡¡and¡¡keep¡¡certain¡¡information¡¡private¡£¡¡¡¡



Defining¡¡the¡¡Interfaces¡¡



The¡¡core¡¡of¡¡the¡¡lighting¡¡controller¡¡is¡¡to¡¡control¡¡the¡¡lighting¡¡in¡¡a¡¡room¡¡that¡¡is¡¡part¡¡of¡¡the¡¡building¡£¡¡¡¡

We¡¡can¡¡define¡¡and¡¡organize¡¡the¡¡rooms¡¡by¡¡using¡¡interfaces¡£¡¡We¡¡need¡¡four¡¡interfaces£º¡¡¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡IRoom£º¡¡A¡¡placeholder¡¡interface¡¡for¡¡the¡¡idea¡¡of¡¡a¡¡room¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡INoRemoteControlRoom£º¡¡An¡¡interface¡¡for¡¡rooms¡¡that¡¡should¡¡not¡¡be¡¡controlled¡¡by¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lighting¡¡controller¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡IRemoteControlRoom£º¡¡An¡¡interface¡¡for¡¡rooms¡¡that¡¡should¡¡be¡¡pletely¡¡controlled¡¡by¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lighting¡¡controller¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡ISensorRoom£º¡¡An¡¡interface¡¡for¡¡rooms¡¡whose¡¡control¡¡is¡¡based¡¡on¡¡state¡¡£¨whether¡¡or¡¡not¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡person¡¡is¡¡in¡¡the¡¡room£©¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡222¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

200¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡8¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡CO¡¡M¡¡P¡¡O¡¡N¡¡E¡¡N¡¡TO¡¡R¡¡IE¡¡N¡¡T¡¡E¡¡D¡¡¡¡AR¡¡C¡¡HI¡¡TE¡¡CT¡¡U¡¡R¡¡E¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡interfaces¡¡for¡¡the¡¡rooms¡¡where¡¡lighting¡¡may¡¡be¡¡controlled£»¡¡IRemoteControlRoom¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ISensorRoom£»¡¡will¡¡depend¡¡on¡¡certain¡¡pieces¡¡of¡¡logic¡£¡¡The¡¡interfaces¡¡will¡¡need¡¡to¡¡provide¡¡input¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡data¡¡and¡¡accept¡¡output¡¡data¡£¡¡The¡¡logic¡¡might¡¡also¡¡seek¡¡input¡¡from¡¡other¡¡sources£»¡¡such¡¡as¡¡time¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡day¡¡or¡¡amount¡¡of¡¡sunlight¡¡outdoors¡£¡¡It¡¡boils¡¡down¡¡to¡¡defining¡¡some¡¡type¡¡of¡¡logic¡¡that¡¡the¡¡kernel¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡implements¡£¡¡This¡¡is¡¡key£»¡¡and¡¡it¡¡relates¡¡to¡¡the¡¡children¡­and¡­parent¡¡issue¡£¡¡While¡¡you¡¡accept¡¡your¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡children¡¡as¡¡being¡¡intelligent¡¡beings¡¡that¡¡can¡¡make¡¡decisions£»¡¡at¡¡the¡¡end¡¡of¡¡the¡¡day£»¡¡it¡¡is¡¡usually¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡parent¡¡who¡¡makes¡¡the¡¡final¡¡decisions¡£¡¡Likewise£»¡¡while¡¡your¡¡kernel¡¡might¡¡accept¡¡input¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡potential¡¡decisions£»¡¡the¡¡kernel¡¡makes¡¡the¡¡final¡¡decisions¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Defining¡¡IRoom£»¡¡a¡¡Placeholder¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡design¡¡purposes£»¡¡the¡¡simplest¡¡and¡¡base¡¡idea¡¡is¡¡the¡¡room¡¡itself£»¡¡which¡¡can¡¡be¡¡defined¡¡as¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡follows¡¡£¨in¡¡the¡¡controller¡¡library¡¡¡¡LibLightingSystem£©£º¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IRoom¡¡¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡interface¡¡does¡¡not¡¡have¡¡any¡¡methods¡¡or¡¡properties¡£¡¡It¡¡is¡¡called¡¡a¡¡placeholder¡¡interface¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡placeholder¡¡type¡¡serves¡¡no¡¡other¡¡purpose¡¡than¡¡identifying¡¡that¡¡the¡¡implementation¡¡is¡¡of¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡certain¡¡type¡£¡¡Placeholder¡¡interfaces¡¡make¡¡it¡¡simpler¡¡to¡¡group¡¡objects¡¡that¡¡have¡¡certain¡¡capabilities¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imagine¡¡defining¡¡objects¡¡without¡¡a¡¡placeholder¡¡interface£»¡¡something¡¡like¡¡this£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Type1¡¡¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Type2¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Looking¡¡at¡¡Type1¡¡and¡¡Type2£»¡¡you¡¡cannot¡¡see¡¡any¡¡correlation¡¡between¡¡the¡¡two¡¡types£»¡¡there¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡no¡¡way¡¡to¡¡say¡¡that¡¡Type1¡¡and¡¡Type2¡¡have¡¡anything¡¡in¡¡mon¡£¡¡£¨Well£»¡¡technically¡¡there¡¡is¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡correlation¡¡in¡¡that¡¡both¡¡types¡¡are¡¡derived¡¡from¡¡Object£»¡¡but¡¡that¡¡type¡¡of¡¡correlation¡¡is¡¡like¡¡saying¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡all¡¡people¡¡are¡¡humans¡££©¡¡Using¡¡a¡¡placeholder¡¡interface£»¡¡Type1¡¡and¡¡Type2¡¡can¡¡be¡¡correlated£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Type1¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡IRoom¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡Type2¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡IRoom¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¡¡¡£¡¡¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡rooms¡¡As¡¡IRoom£¨£©¡¡=¡¡New¡¡IRoom£¨£©¡¡£ûNew¡¡Type1£¨£©£»¡¡New¡¡Type2£¨£©£ý¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Having¡¡Type1¡¡and¡¡Type2¡¡implement¡¡the¡¡¡¡IRoom¡¡interface£»¡¡which¡¡means¡¡do¡¡nothing¡¡other¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡than¡¡subclass¡¡IRoom£»¡¡establishes¡¡a¡¡correlation¡¡between¡¡Type1¡¡and¡¡Type2¡£¡¡The¡¡correlation¡¡is¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡both¡¡Type1¡¡and¡¡Type2¡¡are¡¡rooms¡£¡¡We¡¡have¡¡no¡¡idea¡¡what¡¡kind¡¡of¡¡rooms£»¡¡and¡¡we¡¡have¡¡no¡¡idea¡¡if¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡rooms¡¡are¡¡in¡¡the¡¡same¡¡building¡£¡¡We¡¡only¡¡know¡¡that¡¡they¡¡are¡¡rooms¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡use¡¡of¡¡placeholder¡¡interfaces¡¡is¡¡very¡¡important¡¡in¡¡kernel¡¡design¡£¡¡Placeho

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

Äã¿ÉÄÜϲ»¶µÄ