VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ65²¿·Ö
°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡Figure¡¡8¡5£»¡¡the¡¡individual¡¡boxes¡¡represent¡¡a¡¡single¡¡¡¡assembly¡£¡¡Each¡¡assembly¡¡serves¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡unique¡¡purpose£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Definitions£º¡¡An¡¡assembly¡¡that¡¡contains¡¡all¡¡interfaces¡¡used¡¡by¡¡all¡¡of¡¡the¡¡other¡¡assemblies¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡represents¡¡a¡¡single¡¡assembly¡¡that¡¡changes¡¡very¡¡rarely¡¡and¡¡is¡¡a¡¡cornerstone¡¡of¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡application¡£¡¡Along¡¡with¡¡interfaces£»¡¡you¡¡would¡¡add¡¡general¡¡utility¡¡classes¡¡that¡¡all¡¡assem
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡blies¡¡would¡¡reference¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡User£º¡¡The¡¡main¡¡application¡¡that¡¡interacts¡¡with¡¡the¡¡interfaces¡¡of¡¡objects¡¡that¡¡are¡¡imple
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mented¡¡in¡¡either¡¡the¡¡Kernel¡¡or¡¡¡¡Implementations¡¡assemblies¡£¡¡The¡¡User¡¡assembly¡¡is¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡responsible¡¡for¡¡wiring¡¡together¡¡all¡¡of¡¡the¡¡types¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Kernel£º¡¡An¡¡assembly¡¡that¡¡defines¡¡the¡¡main¡¡functionality¡¡of¡¡the¡¡application¡¡and¡¡manipu
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lates¡¡instances¡¡that¡¡implement¡¡interfaces¡¡from¡¡the¡¡Definitions¡¡assembly¡£¡¡The¡¡kernel¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡does¡¡not¡¡know¡¡where¡¡the¡¡interfaces¡¡are¡¡implemented£»¡¡and¡¡it¡¡expects¡¡some¡¡other¡¡piece¡¡of¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡to¡¡know¡¡where¡¡the¡¡implementations¡¡are¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Implementations£º¡¡An¡¡assembly¡¡that¡¡contains¡¡the¡¡implementations¡¡of¡¡the¡¡interfaces¡¡that¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡kernel¡¡manipulates¡£¡¡The¡¡programmer¡¡may¡¡create¡¡a¡¡single¡¡implementation¡¡assembly¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡multiple¡¡assemblies¡£¡¡The¡¡implementations¡¡are¡¡only¡¡aware¡¡of¡¡the¡¡Definitions¡¡assembly£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡they¡¡are¡¡unaware¡¡of¡¡the¡¡Kernel¡¡assembly¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Building¡¡a¡¡plete¡¡Application¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡All¡¡of¡¡the¡¡code¡¡illustrated¡¡thus¡¡far¡¡is¡¡related¡¡to¡¡the¡¡kernel£»¡¡and¡¡it¡¡would¡¡seem¡¡that¡¡our¡¡applica
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tion¡¡is¡¡plete¡£¡¡In¡¡reality£»¡¡the¡¡kernel¡¡has¡¡done¡¡nothing¡¡other¡¡than¡¡organize¡¡and¡¡manipulate¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡rooms¡£¡¡The¡¡kernel¡¡has¡¡not¡¡defined¡¡any¡¡implementations¡¡for¡¡a¡¡particular¡¡room¡£¡¡Now¡¡let¡¯s¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡see¡¡how¡¡to¡¡define¡¡some¡¡rooms¡¡and¡¡use¡¡the¡¡rooms¡¡in¡¡the¡¡context¡¡of¡¡the¡¡kernel¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡idea¡¡is¡¡to¡¡enable¡¡a¡¡developer¡¡to¡¡add¡¡functionality¡¡to¡¡the¡¡kernel¡¡without¡¡affecting¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡of¡¡the¡¡kernel¡£¡¡The¡¡example¡¡that¡¡we¡¡will¡¡go¡¡through¡¡defines¡¡a¡¡couple¡¡of¡¡rooms¡¡in¡¡a¡¡museum¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨the¡¡Museum¡¡project£©¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡implementation¡¡of¡¡the¡¡Home¡¡project¡¡is¡¡not¡¡discussed¡¡here£»¡¡but¡¡it¡¡is¡¡available¡¡in¡¡this¡¡book¡¯s¡¡down
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡loadable¡¡source¡¡code¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Defining¡¡Some¡¡Rooms¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡rooms¡¡are¡¡defined¡¡in¡¡a¡¡separate¡¡assembly¡¡called¡¡Museum¡¡and¡¡are¡¡not¡¡part¡¡of¡¡the¡¡kernel¡£¡¡The¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡following¡¡is¡¡an¡¡example¡¡of¡¡a¡¡room¡¡implementation¡£¡¡Again£»¡¡remember¡¡to¡¡include¡¡a¡¡reference¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡LibLightingSystem¡¡£¨right¡click¡¡References¡¡in¡¡Museum¡¡and¡¡select¡¡Add¡¡Reference¡¡then¡¡Projects¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡LibLightingSystem£©¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡245¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡223¡¡
¡£¡¡¡£¡¡¡£¡¡
Imports¡¡LibLightingSystem¡¡
¡¡¡¡¡¡¡¡Friend¡¡Class¡¡PrivateRoom¡¡£º¡¡Implements¡¡INoRemoteControlRoom¡¡¡¡
¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡Friend¡¡Class¡¡PublicRoom¡¡£º¡¡Implements¡¡ISensorRoom¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡IsPersonInRoom£¨£©¡¡As¡¡Boolean¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ISensorRoom¡£IsPersonInRoom¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡False¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Private¡¡_lightLevel¡¡As¡¡Double¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡LightLevel£¨£©¡¡As¡¡Double¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡ISensorRoom¡£LightLevel¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡_lightLevel¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡LightSwitch£¨ByVal¡¡lightState¡¡As¡¡Boolean£©¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡IRemoteControlRoom¡£LightSwitch¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡lightState¡¡Then¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_lightLevel¡¡=¡¡1¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Else¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_lightLevel¡¡=¡¡0¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡DimLight£¨ByVal¡¡level¡¡As¡¡Double£©¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Implements¡¡IRemoteControlRoom¡£DimLight¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_lightLevel¡¡=¡¡level¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡two¡¡room¡¡declarations£»¡¡PrivateRoom¡¡and¡¡¡¡PublicRoom£»¡¡are¡¡both¡¡internal¡¡to¡¡the¡¡assembly¡£¡¡¡¡
Each¡¡room¡¡implements¡¡the¡¡interface¡¡that¡¡it¡¡deems¡¡appropriate¡£¡¡PrivateRoom¡¡implements¡¡the¡¡¡¡
interface¡¡INoRemoteControlRoom£»¡¡indicating¡¡that¡¡LightingController¡¡should¡¡leave¡¡the¡¡room¡¡alone¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡PublicRoom¡¡implements¡¡ISensorRoom£»¡¡indicating¡¡that¡¡it¡¡will¡¡tell¡¡the¡¡controller¡¡when¡¡a¡¡person¡¡is¡¡¡¡
in¡¡the¡¡room¡¡and¡¡allow¡¡itself¡¡to¡¡be¡¡controlled¡£¡¡The¡¡implementation¡¡of¡¡¡¡PublicRoom¡¡is¡¡trivial¡¡and¡¡¡¡
frankly¡¡not¡¡that¡¡useful£»¡¡but¡¡it¡¡illustrates¡¡the¡¡bare¡¡minimum¡¡of¡¡what¡¡needs¡¡to¡¡be¡¡implemented¡£¡¡¡¡
In¡¡a¡¡production¡¡environment£»¡¡PublicRoom¡¡would¡¡have¡¡access¡¡to¡¡external¡¡devices¡¡such¡¡as¡¡a¡¡¡¡
heat¡¡sensor¡¡and¡¡lights¡£¡¡The¡¡objective¡¡of¡¡PublicRoom¡¡would¡¡be¡¡to¡¡give¡¡and¡¡take¡¡signals¡¡from¡¡the¡¡¡¡
LightingController¡¡and¡¡take¡¡action¡£¡¡It¡¡is¡¡not¡¡up¡¡to¡¡PublicRoom¡¡to¡¡ask¡¡whether¡¡or¡¡not¡¡a¡¡decision¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡246¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
224¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡correct¡£¡¡For¡¡example£»¡¡if¡¡¡¡LightingController¡¡indicated¡¡to¡¡turn¡¡the¡¡light¡¡off¡¡even¡¡though¡¡a¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡person¡¡is¡¡in¡¡the¡¡room£»¡¡then¡¡PublicRoom¡¡would¡¡not¡¡ask¡¡why¡¡the¡¡light¡¡is¡¡being¡¡turned¡¡off¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡When¡¡you¡¡are¡¡designing¡¡a¡¡kernel¡like¡¡architecture£»¡¡the¡¡implementations¡¡are¡¡realizations¡¡of¡¡ideas¡¡and¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡should¡¡never¡¡question¡¡the¡¡controller¡£¡¡The¡¡implementations¡¡might¡¡not¡¡be¡¡aware¡¡of¡¡a¡¡bigger¡¡picture¡¡and¡¡thus¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡might¡¡prevent¡¡an¡¡algorithm¡¡from¡¡functioning¡¡properly¡£¡¡Of¡¡course£»¡¡the¡¡exception¡¡to¡¡this¡¡rule¡¡is¡¡if¡¡the¡¡decision¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡would¡¡cause¡¡physical¡¡damage¡¡or¡¡cause¡¡the¡¡program¡¡to¡¡crash¡£¡¡In¡¡that¡¡case£»¡¡the¡¡implementation¡¡should¡¡throw¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡an¡¡exception£»¡¡indicating¡¡that¡¡the¡¡decision¡¡is¡¡faulty¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Instantiating¡¡PublicRoom¡¡and¡¡PrivateRoom¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡described¡¡in¡¡the¡¡previous¡¡chapter£»¡¡when¡¡you¡¡are¡¡developing¡¡ponents£»¡¡you¡¡want¡¡to¡¡separate¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡interfaces¡¡from¡¡the¡¡implementations¡£¡¡This¡¡gives¡¡you¡¡the¡¡flexibility¡¡to¡¡change¡¡the¡¡imple
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mentation¡¡in¡¡an¡¡assembly¡¡without¡¡requiring¡¡the¡¡users¡¡of¡¡the¡¡assembly¡¡to¡¡repile¡¡their¡¡code¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡instantiate¡¡the¡¡implementations£»¡¡you¡¡need¡¡a¡¡factory£»¡¡and¡¡the¡¡museum¡¡with¡¡its¡¡PrivateRoom¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡PublicRoom¡¡implementations¡¡is¡¡no¡¡different¡£¡¡However£»¡¡a¡¡builder¡¡method¡¡that¡¡assembles¡¡a¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡building¡¡of¡¡potential¡¡PrivateRoom¡¡and¡¡¡¡PublicRoom¡¡binations¡¡will¡¡be¡¡offered¡¡with¡¡the¡¡museum¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡builder¡¡method¡¡is¡¡useful¡¡because¡¡it¡¡predefines¡¡a¡¡canned¡¡building¡¡that¡¡has¡¡all¡¡the¡¡room¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡groupings¡¡and¡¡rooms¡¡properly¡¡added¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡Think¡¡of¡¡a¡¡builder¡¡method¡¡as¡¡a¡¡way¡¡of¡¡creating¡¡a¡¡predefined¡¡structure£»¡¡thus¡¡saving¡¡users¡¡from¡¡having¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡do¡¡that¡¡themselves¡£¡¡A¡¡builder¡¡method¡¡is¡¡only¡¡a¡¡starting¡¡point£»¡¡and¡¡you¡¡should¡¡be¡¡able¡¡to¡¡manipulate¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡structure¡¡afterward¡¡for¡¡fine¡tuning¡¡purposes¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡is¡¡the¡¡implementation¡¡of¡¡the¡¡museum¡¡factory£»¡¡which¡¡is¡¡added¡¡to¡¡the¡¡project¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Museum¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Module¡¡FactoryRooms¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Function¡¡CreateBuilding£¨£©¡¡As¡¡LightingController¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡controller¡¡As¡¡New¡¡LightingController£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡publicAreas¡¡As¡¡Object¡¡=¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡controller¡£AddRoomGrouping£¨¡¨public¡¡viewing¡¡areas¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡privateAreas¡¡As¡¡Object¡¡=¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡controller¡£AddRoomGrouping£¨¡¨private¡¡viewing¡¡areas¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡controller¡£AddRoomToGrouping£¨publicAreas£»¡¡New¡¡PublicRoom£¨£©£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡controller¡£AddRoomToGrouping£¨privateAreas£»¡¡New¡¡PrivateRoom£¨£©£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡controller¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡247¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡225¡¡
¡¡¡¡¡¡¡¡Public¡¡Function¡¡CreatePrivateRoom£¨£©¡¡As¡¡IRoom¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡PrivateRoom£¨£©¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡Public¡¡Function¡¡CreatePublicRoom£¨£©¡¡As¡¡IRoom¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡PublicRoom£¨£©¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
End¡¡Module¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡implementation¡¡has¡¡three¡¡methods£º¡¡CreateBuilding£¨£©£»¡¡CreatePrivateRoom£¨£©£»¡¡and¡¡¡¡
CreatePublicRoom£¨£©£»¡£¡¡The¡¡fact¡¡that¡¡CreatePrivateRoom£¨£©¡¡and¡¡PrivateRoom£¨£©¡¡have¡¡similar¡¡naming¡¡is¡¡¡¡
purely¡¡coincidental¡£¡¡The¡¡method¡¡could¡¡just¡¡as¡¡well¡¡have¡¡been¡¡called¡¡CreateNonControlledRoom£¨£©¡£¡¡¡¡
The¡¡CreatePrivateRoom£¨£©¡¡and¡¡CreatePublicRoom£¨£©¡¡methods¡¡are¡¡intended¡¡to¡¡define¡¡method¡¡¡¡
identifiers¡¡that¡¡users¡¡can¡¡understand¡£¡¡What¡¡is¡¡instantiated¡¡in¡¡the¡¡method¡¡must¡¡return¡¡an¡¡IRoom¡¡¡¡
instance¡£¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡CreateBuilding£¨£©¡¡method¡¡is¡¡a¡¡builder¡¡method£»¡¡and¡¡it¡¡returns¡¡a¡¡¡¡LightingController¡¡¡¡
instance¡£¡¡It¡¡is¡¡fine¡¡to¡¡return¡¡a¡¡LightingController¡¡instance£»¡¡because¡¡it¡¡is¡¡a¡¡globally¡¡defined¡¡type¡¡¡¡
and¡¡can¡¡serve¡¡as¡¡a¡¡basis¡¡for¡¡the¡¡builder¡¡method¡£¡¡In¡¡the¡¡implementation¡¡of¡¡the¡¡builder¡¡method£»¡¡¡¡
the¡¡room¡¡groupings¡¡and¡¡rooms¡¡are¡¡instantiated¡¡and¡¡added¡¡to¡¡the¡¡LightingController¡¡instance¡£¡¡¡¡
This¡¡is¡¡the¡¡work¡¡that¡¡the¡¡builder¡¡should¡¡save¡¡the¡¡end¡¡user¡£¡¡Additionally£»¡¡by¡¡providing¡¡a¡¡builder¡¡¡¡
method£»¡¡you¡¡avoid¡¡creating¡¡museum¡¡structures¡¡that¡¡have¡¡glaring¡¡errors¡¡in¡¡their¡¡structures¡£¡¡¡¡
¡öNote¡¡¡¡Factory¡¡types¡¡serve¡¡to¡¡instantiate¡¡types¡¡and¡¡define¡¡builder¡¡methods£»¡¡but¡¡can¡¡also¡¡be¡¡used¡¡to¡¡perform¡¡¡¡
generic¡¡structural¡¡operations¡£¡¡Let¡¯s¡¡say¡¡that¡¡in¡¡your¡¡museum¡¡there¡¡is¡¡a¡¡wing£»¡¡which¡¡contains¡¡three¡¡public¡¡¡¡
rooms¡¡and¡¡a¡¡private¡¡room¡£¡¡You¡¡could¡¡define¡¡a¡¡builder¡¡method¡¡that¡¡creates¡¡a¡¡wing£»¡¡and¡¡the¡¡wing¡¡is¡¡added¡¡to¡¡¡¡
an¡¡already¡¡created¡¡building¡£¡¡The¡¡general¡¡idea¡¡behind¡¡the¡¡factory¡¡type¡¡is¡¡to¡¡avoid¡¡errors¡¡and¡¡centralize¡¡repeated¡¡¡¡
instantiations¡£¡¡
Learning¡¡More¡¡About¡¡Private¡¡Classes¡¡and¡¡¡¡
Object¡¡Initialization¡¡
In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡how¡¡to¡¡apply¡¡interfaces£»¡¡implementations£»¡¡and¡¡ponents¡¡in