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

µÚ83²¿·Ö

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

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

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




data¡¡member¡¡Cells¡¡represents¡¡a¡¡function¡¡that¡¡is¡¡executed¡¡to¡¡generate¡¡the¡¡result¡¡of¡¡a¡¡particular¡¡¡¡

cell¡¡that¡¡is¡¡assigned¡¡to¡¡the¡¡data¡¡member¡¡State¡£¡¡Both¡¡data¡¡members¡¡store¡¡and¡¡manipulate¡¡Objects£»¡¡¡¡

which¡¡makes¡¡the¡¡spreadsheet¡¡flexible¡£¡¡However£»¡¡a¡¡gain¡¡in¡¡one¡¡aspect¡¡means¡¡a¡¡reduction¡¡in¡¡¡¡

another¡¡aspect£»¡¡in¡¡this¡¡case£»¡¡the¡¡loss¡¡is¡¡in¡¡performance¡£¡¡But¡¡performance¡¡is¡¡what¡¡algorithmic¡¡¡¡

trading¡¡software¡¡cannot¡¡sacrifice£»¡¡and¡¡native¡¡types¡¡would¡¡be¡¡best¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡To¡¡make¡¡the¡¡spreadsheet¡¡perform¡¡as¡¡fast¡¡as¡¡it¡¡can£»¡¡we¡¡need¡¡to¡¡use¡¡fixed¡­dimension¡¡arrays¡£¡¡¡¡

However£»¡¡with¡¡fixed¡­dimension¡¡arrays£»¡¡we¡¡are¡¡moving¡¡away¡¡from¡¡a¡¡traditional¡¡object¡­oriented¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡312¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

290¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡approach¡£¡¡You¡¡could¡¡argue¡¡that¡¡spreadsheets¡¡are¡¡not¡¡object¡­oriented¡¡at¡¡all¡¡and¡¡are¡¡a¡¡problem¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡respect¡¡to¡¡programmability¡£¡¡I¡¡would¡¡agree¡¡with¡¡that¡¡ment£»¡¡but¡¡spreadsheets¡¡solve¡¡one¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡class¡¡of¡¡problems¡¡very¡¡elegantly¡£¡¡In¡¡the¡¡case¡¡of¡¡financial¡¡trading¡¡software£»¡¡they¡¡solve¡¡the¡¡problem¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡managing¡¡very¡¡large¡¡amounts¡¡of¡¡data¡¡efficiently¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡Object¡­oriented¡¡code¡¡is¡¡maintainable¡¡and¡¡extendable¡£¡¡However£»¡¡object¡­oriented¡¡code¡¡can¡¡be¡¡slow¡£¡¡I¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡have¡¡done¡¡tests¡¡where¡¡I¡¡found¡¡fixed¡­dimension¡¡arrays¡¡perform¡¡two¡¡to¡¡three¡¡times¡¡faster¡¡than¡¡the¡¡equivalent¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡object¡­oriented¡¡application¡£¡¡But¡¡performance¡¡is¡¡not¡¡always¡¡the¡¡primary¡¡consideration¡£¡¡Also£»¡¡fixed¡­dimension¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡arrays¡¡will¡¡not¡¡always¡¡give¡¡you¡¡the¡¡desired¡¡performance¡¡boost£»¡¡because¡¡other¡¡parts¡¡of¡¡your¡¡code¡¡might¡¡be¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡much¡¡slower¡£¡¡Therefore£»¡¡generally£»¡¡you¡¡should¡¡not¡¡use¡¡fixed¡­dimension¡¡arrays¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Cells¡¡data¡¡member¡¡is¡¡a¡¡delegate£»¡¡or¡¡lambda¡¡expression£»¡¡that¡¡is¡¡defined¡¡using¡¡code¡¡similar¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡the¡¡following¡£¡¡When¡¡we¡¡want¡¡to¡¡fill¡¡a¡¡cell£»¡¡we¡¡call¡¡the¡¡appropriate¡¡function¡¡on¡¡CellFactories£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡which¡¡in¡¡turn¡¡returns¡¡the¡¡lambda¡¡expression¡¡that¡¡represents¡¡the¡¡new¡¡value¡¡stored¡¡in¡¡the¡¡cell£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Module¡¡CellFactories¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Function¡¡DoAdd£¨ByVal¡¡cell1¡¡As¡¡Func£¨Of¡¡Object£©£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡cell2¡¡As¡¡Func£¨Of¡¡Object£©£©¡¡As¡¡Func£¨Of¡¡Object£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡Function£¨£©¡¡CType£¨cell1£¨£©£»¡¡Double£©¡¡£«¡¡CType£¨cell2£¨£©£»¡¡Double£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Function¡¡DoMultiply£¨ByVal¡¡cell1¡¡As¡¡Func£¨Of¡¡Object£©£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡cell2¡¡As¡¡Func£¨Of¡¡Object£©£©¡¡As¡¡Func£¨Of¡¡Object£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡Function£¨£©¡¡CType£¨cell1£¨£©£»¡¡Double£©¡¡*¡¡CType£¨cell2£¨£©£»¡¡Double£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Function¡¡FixedValue£¨ByVal¡¡value¡¡As¡¡Object£©¡¡As¡¡Func£¨Of¡¡Object£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡Function£¨£©¡¡value¡¡

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

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡lambda¡¡expressions¡¡can¡¡be¡¡used¡¡to¡¡add¡¡two¡¡cells¡¡together£»¡¡multiply¡¡two¡¡cells¡¡together£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡or¡¡store¡¡a¡¡fixed¡¡value¡£¡¡With¡¡the¡¡lambda¡¡expressions¡¡and¡¡the¡¡spreadsheet£»¡¡you¡¡have¡¡two¡¡pieces¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡source¡¡code¡¡that£»¡¡when¡¡bined£»¡¡have¡¡the¡¡ability¡¡to¡¡solve¡¡plicated¡¡problems¡£¡¡The¡¡key¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡idea¡¡that¡¡you¡¡need¡¡to¡¡take¡¡away¡¡is¡¡that¡¡the¡¡Spreadsheet¡¡class¡¡and¡¡the¡¡lambda¡¡expressions¡¡defined¡¡in¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CellFactories¡¡do¡¡not¡¡know¡¡about¡¡each¡¡other¡£¡¡The¡¡lambda¡¡expressions¡¡could¡¡be¡¡used¡¡in¡¡a¡¡context¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡other¡¡than¡¡a¡¡spreadsheet¡£¡¡The¡¡only¡¡requirement¡¡is¡¡that¡¡the¡¡function¡¡types¡¡and¡¡signatures¡¡match¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡sample¡¡spreadsheet¡¡that¡¡would¡¡be¡¡used¡¡to¡¡add¡¡and¡¡multiply¡¡some¡¡cells¡¡together¡¡would¡¡¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡spreadsheet¡¡As¡¡Spreadsheet¡¡=¡¡New¡¡Spreadsheet£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡spreadsheet¡£Cells£¨1£»¡¡0£©¡¡=¡¡CellFactories¡£FixedValue£¨10¡£0£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡spreadsheet¡£Cells£¨0£»¡¡1£©¡¡=¡¡CellFactories¡£FixedValue£¨10¡£0£©¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡313¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡291¡¡



spreadsheet¡£Cells£¨1£»¡¡2£©¡¡=¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡CellFactories¡£DoAdd£¨spreadsheet¡£Cells£¨1£»¡¡0£©£»¡¡spreadsheet¡£Cells£¨0£»¡¡1£©£©¡¡

spreadsheet¡£Cells£¨2£»¡¡2£©¡¡=¡¡CellFactories¡£DoMultiply£¨spreadsheet¡£Cells£¨1£»¡¡2£©£»¡¡_¡¡

¡¡¡¡¡¡¡¡CellFactories¡£FixedValue£¨2¡£0£©£©¡¡

spreadsheet¡£Execute£¨£©¡¡



Console¡£WriteLine£¨¡¨Contents¡¡of¡¡£¨1£»¡¡2£©£º¡¡¡¨¡¡&¡¡spreadsheet¡£State£¨1£»¡¡2£©¡£ToString£¨£©£©¡¡

Console¡£WriteLine£¨¡¨Contents¡¡of¡¡£¨2£»¡¡2£©£º¡¡¡¨¡¡&¡¡spreadsheet¡£State£¨2£»¡¡2£©¡£ToString£¨£©£©¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡sample¡¡code¡¡illustrates¡¡a¡¡rudimentary¡¡example¡¡of¡¡a¡¡spreadsheet¡¡and¡¡how¡¡lambda¡¡¡¡

expressions¡¡can¡¡be¡¡used¡£¡¡In¡¡this¡¡chapter£»¡¡the¡¡focus¡¡will¡¡be¡¡on¡¡how¡¡to¡¡create¡¡a¡¡spreadsheet¡¡¡¡

implementation¡¡that¡¡is¡¡effective£»¡¡mostly¡¡object¡­oriented£»¡¡and¡¡maintainable¡£¡¡



Architecting¡¡a¡¡Server¡­Side¡¡Spreadsheet¡¡¡¡



To¡¡architect¡¡a¡¡server¡¡spreadsheet£»¡¡the¡¡following¡¡requirements¡¡must¡¡be¡¡met£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Performance£º¡¡Wherever¡¡possible£»¡¡the¡¡design¡¡should¡¡not¡¡sacrifice¡¡performance¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Usability£º¡¡The¡¡server¡­side¡¡spreadsheet¡¡must¡¡be¡¡easy¡¡to¡¡program¡¡from¡¡a¡¡Visual¡¡Basic¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡perspective¡£¡¡If¡¡the¡¡server¡­side¡¡spreadsheet¡¡is¡¡too¡¡plex¡¡or¡¡difficult¡¡to¡¡understand£»¡¡it¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡not¡¡be¡¡used¡¡properly£»¡¡potentially¡¡incurring¡¡errors¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Maintainability£º¡¡The¡¡server¡­side¡¡spreadsheet¡¡implementation¡¡should¡¡be¡¡somewhat¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡maintainable¡£¡¡Otherwise£»¡¡bugs¡¡could¡¡creep¡¡into¡¡the¡¡code£»¡¡impeding¡¡the¡¡spreadsheet¡¯s¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡effective¡¡use¡£¡¡



¡¡¡¡¡¡¡¡¡¡Not¡¡listed¡¡is¡¡the¡¡requirement¡¡for¡¡extensibility¡£¡¡A¡¡spreadsheet¡¡by¡¡itself¡¡is¡¡not¡¡extensible¡¡¡¡

because¡¡it¡¡implements¡¡a¡¡certain¡¡paradigm£»¡¡which¡¡is¡¡a¡¡two¡­dimensional¡¡document¡¡of¡¡numbers¡¡¡¡

and¡¡calculations¡£¡¡

¡¡¡¡¡¡¡¡¡¡And¡¡if¡¡you¡¡are¡¡wondering¡¡where¡¡the¡¡spreadsheet¡¡code¡¡es¡¡from£»¡¡it¡¡is¡¡a¡¡subset¡¡of¡¡the¡¡¡¡

actual¡¡code¡¡that¡¡I¡¡use¡¡in¡¡my¡¡own¡¡security¡¡trading¡¡system¡£¡¡



¡öNote¡¡¡¡To¡¡code¡¡the¡¡spreadsheet¡¡to¡¡do¡¡more¡¡than¡¡it¡¡is¡¡originally¡¡designed¡¡for¡¡might¡¡be¡¡an¡¡interesting¡¡goal£»¡¡¡¡

but¡¡not¡¡one¡¡that¡¡is¡¡worth¡¡pursuing¡£¡¡Sometimes¡¡it¡¡is¡¡best¡¡to¡¡solve¡¡a¡¡problem£»¡¡and¡¡leave¡¡paradigm¡¡thinking¡¡for¡¡¡¡

another¡¡time¡£¡¡I¡¡have¡¡seen¡¡developers¡¡think¡¡about¡¡paradigms£»¡¡not¡¡finish¡¡their¡¡code£»¡¡and¡¡then¡¡have¡¡the¡¡code¡¡¡¡

made¡¡obsolete¡¡by¡¡a¡¡paradigm¡¡that¡¡they¡¡did¡¡not¡¡consider¡£¡¡



¡¡¡¡¡¡¡¡¡¡Three¡¡projects¡¡are¡¡defined¡¡for¡¡this¡¡example£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Devspace¡£Trader¡£mon£º¡¡A¡¡class¡¡library¡¡that¡¡is¡¡a¡¡distilled¡¡form¡¡of¡¡my¡¡trading¡¡library¡£¡¡I¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡decided¡¡to¡¡include¡¡such¡¡a¡¡library¡¡to¡¡give¡¡you¡¡a¡¡taste¡¡of¡¡how¡¡a¡¡production¡¡class¡¡library¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡looks¡¡and¡¡feels¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡ServerSideSpreadsheet£º¡¡A¡¡class¡¡library¡¡that¡¡represents¡¡the¡¡implementation¡¡of¡¡a¡¡server

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡side¡¡spreadsheet¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡TestServerSideSpreadsheet£º¡¡A¡¡console¡¡application¡¡that¡¡tests¡¡the¡¡ServerSideSpreadsheet¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡project¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡314¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

292¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Designing¡¡the¡¡Architecture¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡original¡¡implementation¡¡of¡¡the¡¡spreadsheet¡¡code¡¡provides¡¡a¡¡great¡¡starting¡¡point¡£¡¡Using¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lambda¡¡expressions¡¡to¡¡calculate¡¡the¡¡state¡¡of¡¡a¡¡cell¡¡makes¡¡it¡¡easy¡¡to¡¡create¡¡a¡¡worksheet¡¡of¡¡numbers¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡What¡¡is¡¡not¡¡so¡¡great¡¡is¡¡the¡¡fact¡¡that¡¡the¡¡class¡¡SpreadSheet¡¡is¡¡a¡¡single¡¡worksheet¡£¡¡Most¡¡spreadsheets¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡applications¡¡£¨like¡¡Microsoft¡¡Excel£©¡¡offer¡¡the¡¡ability¡¡to¡¡create¡¡multiple¡¡worksheets¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡server¡­side¡¡spreadsheet¡¡that¡¡we¡¡will¡¡create¡¡will¡¡consist¡¡of¡¡two¡¡concepts£º¡¡workbook¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡worksheet£»¡¡as¡¡illustrated¡¡in¡¡Figure¡¡11¡­1¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡11¡­1¡£¡¡Spreadsheet¡¡design¡¡based¡¡on¡¡workbook¡¡and¡¡worksheet¡¡types¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡workbook¡¡is¡¡a¡¡type¡¡that¡¡acts¡¡like¡¡a¡¡collection¡¡class¡¡of¡¡the¡¡worksheet¡¡type¡£¡¡The¡¡work

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡sheet¡¡type¡¡is¡¡an¡¡individual¡¡spreadsheet¡¡of¡¡fixed¡¡dimension¡¡that¡¡is¡¡responsible¡¡for¡¡storing¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡state£»¡¡and¡¡the¡¡cell¡¡calculations¡¡reference¡¡the¡¡individual¡¡lambda¡¡expressions¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡workbook¡¡and¡¡worksheet¡¡could¡¡be¡¡defined¡¡as¡¡interfaces¡¡or¡¡as¡¡classes¡£¡¡Which¡¡would¡¡be¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡better£¿¡¡Let¡¯s¡¡assume¡¡that¡¡workbook¡¡will¡¡be¡¡defined¡¡as¡¡an¡¡interface¡¡and¡¡then¡¡implemented¡¡by¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡class¡£¡¡The¡¡approach¡¡is¡¡a¡¡mitment¡¡to¡¡a¡¡ponent¡¡architecture£»¡¡allowing¡¡you¡¡to¡¡implement¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡multiple¡¡types¡¡of¡¡workbooks¡£¡¡However£»¡¡the¡¡likelihood¡¡of¡¡implementing¡¡multiple¡¡workbook¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡types¡¡is¡¡rather¡¡remote£»¡¡so¡¡why¡¡use¡¡interfaces£¿¡¡Because¡¡interfaces¡¡fit¡¡better¡¡into¡¡a¡¡bigger¡¡context¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡say¡¡that¡¡you¡¡have¡¡pleted¡¡your¡¡super¡­duper¡¡server¡­side¡¡application¡¡and¡¡want¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡programmatically¡¡share¡¡the¡¡code¡¡with¡¡multiple¡¡machines¡£¡¡Having¡¡one¡¡puter¡¡call¡¡¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡functionality¡¡on¡¡another¡¡machine¡¡is¡¡almost¡¡trivial£»¡¡but¡¡to¡¡attain¡¡the¡¡best¡¡performance¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡resource¡¡usage£»¡¡you¡¡should¡¡use¡¡interfaces¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Defining¡¡the¡¡Server¡¡Spreadsheet¡¡Interfaces¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Defining¡¡the¡¡interfaces¡¡for¡¡the¡¡server¡¡spreadsheets¡¡is¡¡actually¡¡rather¡¡plicated¡¡because¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡requirements¡£¡¡The¡¡requirements¡¡state¡¡performance¡¡and¡¡usability¡¡are¡¡important£»¡¡which£»¡¡in¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡case£»¡¡is¡¡asking¡¡quite¡¡a¡¡bit£»¡¡as¡¡you¡¡will¡¡see¡¡as¡¡we¡¡work¡¡through¡¡the¡¡example¡£¡¡Let¡¯s¡¡start¡¡with¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡bottom¡­up¡¡development¡¡approach¡¡and¡¡outline¡¡the¡¡interfaces¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Defining¡¡the¡¡Debug¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Because¡¡the¡¡spreadsheet¡¡is¡¡from¡¡a¡¡production¡¡coding¡¡example£»¡¡included¡¡in¡¡the¡¡discussion¡¡will¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡be¡¡pieces¡¡of¡¡code¡¡that¡¡demonstrate¡¡good¡¡programming¡¡practices¡£¡¡The¡¡following¡¡is¡¡the¡¡base¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface¡¡for¡¡all¡¡of¡¡my¡¡interfaces£»¡¡which¡¡is¡¡defined¡¡in¡¡the¡¡Devspace¡£Trader¡£mon¡¡project¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IDebug¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Property¡¡Debug£¨£©¡¡As¡¡Boolean¡¡

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


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡315¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡293¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡IDebug¡¡interface¡¡has¡¡a¡¡single¡¡Boolean¡¡property¡¡called¡¡Debug£»¡¡which¡¡can¡¡be¡¡assigned¡¡and¡¡¡¡

retrieved¡£¡¡The¡¡idea¡¡behind¡¡th

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

Äã¿ÉÄÜϲ»¶µÄ