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

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

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




                  End Get 

              End Property 



              Public ReadOnly Property OneLeft�┌� As SheetCoordinate 

                  Get 

                      Return New SheetCoordinate��Me。Row�察。�Me。Column 1���� 

                  End Get 

              End Property 



              Public ReadOnly Property OneRight�┌� As SheetCoordinate 

                  Get 

                      Return New SheetCoordinate��Me。Row�察。�Me。Column �� 1���� 

                  End Get 

              End Property 



          End Structure 



               In the declaration of SheetCoordinate�察�notice that Structure is used rather than Class。  

          We could have used a class�察�but SheetCoordinate serves the purpose of being a piece of data。  

          SheetCoordinate is a type where you store information that is used by another type。 A data type  

          might do some processing�察�but only to make it easier to manipulate the data。 For example�察 �

          notice how SheetCoordinate has properties to generate a new instance of SheetCoordinate that  

          might be one row higher or lower�察�or a column to the right or left。 

               The next step is to extend the worksheet definition and use  generics to define the  

          type of worksheet。 The following is the plete definition of the  IWorksheet。 These methods  


´´´´´´´´´´´´´´´´´´´´´´Page 319´´´´´´´´´´´´´´´´´´´´´´´

                                                     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 297 



are used to calculate the values of cells in the worksheet and work with the contents of individual  

cells ��the state of those cells��。 We can also assign the function that carries out the calculation of  

a cell¨s contents�察�using either a SheetCoordinate type or the row and column coordinates。 



Public Interface IWorksheet��Of BaseType�� 

    Inherits IWorksheetBase 



    Sub AssignCellCalculation��ByVal coords As SheetCoordinate�察�_ 

        ByVal cb As Func��Of IWorksheet��Of BaseType���察�Integer�察�Integer�察�BaseType���� 



    Sub AssignCellCalculation��ByVal row As Integer�察�ByVal col As Integer�察�_ 

        ByVal cb As Func��Of IWorksheet��Of BaseType���察�Integer�察�Integer�察�BaseType���� 



    Sub AssignColCalculation��ByVal col As Integer�察�_ 

                             ByVal cb As Func��Of IWorksheet��Of BaseType���察�_  

                             Integer�察�Integer�察�BaseType���� 

    Sub Calculate�┌� 



    Function Calculate��ByVal coords As SheetCoordinate�� As BaseType 

     

    Function Calculate��ByVal row As Integer�察�ByVal col As Integer�� As BaseType 



    Sub CalculateCol��ByVal col As Integer�� 



    Sub CalculateRow��ByVal row As Integer�� 



    Function GetCellState��ByVal coords As SheetCoordinate�� As BaseType 



    Function GetCellState��ByVal row As Integer�察�ByVal col As Integer�� As BaseType 



    Sub SetCellState��ByVal coords As SheetCoordinate�察�ByVal val As BaseType�� 



    Sub SetCellState��ByVal row As Integer�察�ByVal col As Integer�察�_ 

                     ByVal val As BaseType�� 



    ReadOnly Property Data�┌� As BaseType �┌撮� 

End Interface 



     The declaration of IWorksheet is as a  generics type�察�where BaseType is a  generics  

parameter that represents the type of the spreadsheet。 Since IWorksheet is a type of spreadsheet�察 �

it subclasses the IWorksheetBase interface�察�allowing IWorksheet to be part of a mixed collection  

of IWorksheet instances。 The IWorksheet interface is fairly plex and contains many methods。  

However�察�here we are focusing on the interface concept�察�rather than the individual methods。 

     Look at the bolded parts and notice how the interface is specific about the operations�察�but  

vague about the type used in the operations。 This is what you want to achieve when using   

generics。 You want to take a high´level approach and indicate which operations are available�察 �

but leave out the types being manipulated in the operations。 The types will be specified later by  

another programmer。 


´´´´´´´´´´´´´´´´´´´´´´Page 320´´´´´´´´´´´´´´´´´´´´´´´

298        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 



           *Note  The technique of having a  generics type ��such as IWorksheet�� subclass a non´ generics  

           type ��such as  IWorksheetBase�� allows you to identify the general type that you are trying to describe with  

           some specialization in the  generics type declaration。 



           Defining the IWorkbook Interface 



           Now that we¨ve pleted the IWorksheet��Of BaseType�� and  IWorksheetBase interfaces�察�we  

           can define the workbook interface。 The workbook interface will not be a  generics type�察 �

           since a workbook will contain multiple worksheet types。 However�察�as you will see�察�we can optimize  

           this interface to make it easier to use the workbook。  

                 For the moment�察�let¨s consider the plain´vanilla IWorkbook interface with no  generics  

           types�察�which is defined as follows in the ServerSideSpreadsheet�此�



           Imports System。Reflection 

           Imports Devspace。Trader。mon 



            _ 

           Public Interface IWorkbook 

               Inherits IDebug 



               ReadOnly Property Identifier�┌� As String 

               Default Property Item��ByVal identifier As String�� As IWorksheetBase 

           End Interface 



                The IWorkbook interface defines an Identifier property and a default property Item。 Notice  

           how the attribute DefaultMember is defined to indicate the default property identifier ��it is from  

           the System。Reflection namespace��。 Any class that implements IWorkbook is expected to contain  

           multiple references to IWorksheet��Of BaseType�� instances。 How those references are managed  

           is not the responsibility of the IWorkbook interface�察�but of the IWorkbook interface implementation。  



           *Note  The IWorkbook interface does not provide a Clear�┌� method to reset the workbook and delete all  

           of the referenced worksheets。 It would seem logical to have a Clear�┌� method�察�but in a garbage´collected  

           environment�察�that¨s pletely unnecessary。 If you don¨t want to use a workbook anymore�察�just don¨t refer

           ence it�察�and the garbage collector will take care of the rest。 Think of it as having the option of serving dinner  

           to your guests on real plates or paper plates。 Real plates might seem better�察�but they break and you need to  

           wash them。 Paper plates are used once and thrown away。 Of course�察�with paper plates you have recycling  

           issues that you don¨t have in �察�because the memory is recycled for you。 



                The property  Identifier identifies the workbook represented by the current  IWorkbook  

           object。 The identifier might be a path or file name and is pletely dependent on the imple

           mentation of IWorkbook。 


´´´´´´´´´´´´´´´´´´´´´´Page 321´´´´´´´´´´´´´´´´´´´´´´´

                                                       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 299 



     The default property�察�Item�察�is the primary way of getting and retrieving worksheets�察�where  

each worksheet is referenced using a string identifier。 The identifier does not need to be a string! 

it could have been a custom type�察�enumeration�察�or interface that is implemented。 Using a string  

keeps things simple�察�but there are maintenance issues。 

     Let¨s say all workbooks have a configuration worksheet。 So for most of the code�察�the string  

identifier  ;configuration; is used。 However�察�a new programmer decides to use  ;Configuration;  

��with a capital C��。 This slight change will cause problems because  ;configuration; is meant to  

have a lowercase c。 Here¨s the example�此�



Dim workbook As IWorkbook 

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