嗔秤戻幣�哉膵�云利匈嬉蝕湊蛸賜�塋床四衲���萩晦編報炎嘔囚^泡仟 ̄云利匈�《超噌�殻窟�嵌虜隆輓麈觚翹瀘卉韮�仍仍�。� 烏御危列
昂昂慕汐 卦指云慕朕村 厘議慕尺 厘議慕禰 TXT畠云和墮 序秘慕杏 紗秘慕禰

VB2008貫秘壇欺娼宥(PDF鯉塀哂猟井)-及138嫗

梓囚徒貧圭�鮗� ○ 賜 ★ 辛酔堀貧和鍬匈��梓囚徒貧議 Enter 囚辛指欺云慕朕村匈��梓囚徒貧圭�鮗� ● 辛指欺云匈競何��
!!!!隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��




          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�
卦指朕村 貧匯匈 和匯匈 指欺競何 壘��1�� 家��1��
隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��
梁椣戻幣�� 梁心弌傍議揖扮窟燕得胎��傍竃徭失議心隈才凪万弌誌育断蛍�輌臆惨軼僑〃�燕慕得珊辛參資誼持蛍才将刮襲潜��範寔亟圻幹慕得 瓜寡追葎娼得辛參資誼寄楚署衛、持蛍才将刮襲潜填��