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。
小说推荐
- oracle从入门到精通(PDF格式)
- -Page 1-Oracle 从入门到精通-Page 2-资源来自网络,仅供学习 Oracle 从入门到精通一、SQL 8
- 最新章:第37章
- C语言游戏编程从入门到精通(PDF格式)
- -Page 1-Page 2-Page 3-Page 4-Page 5-Page 6-Page 7-Page 8-Page 9-Page 10-Page 11-Page 12-Page 13-Page 14
- 最新章:第4章
- Java编程思想第4版[中文版](PDF格式)
- -Page 1-Page 2《Thinking In Java》中文版作者:Bruce Eckel主页:http/BruceEckel.编译:Trans Bot主页:http/memberease~transbot致谢-献给那些直到现在仍在孜孜不倦创造下一代计算机语言的人们!指导您利用万维网的语言进
- 最新章:第295章
- 深入浅出MFC第2版(PDF格式)
- -Page 1-Page 2-山高月小山高月小 水落石出水落石出山高月小山高月小 水落石出水落石出-Page 3-深入淺出MFC(第版 使用Visual C 5.0 MFC 4.2)Dissecting MFC(Second Edition Using Visual C 5.0 MFC 4.2)侯俊
- 最新章:第309章
- VC语言6.0程序设计从入门到精通
- -Page 1-Visual C 6.0 程序设计从入门到精通求是科技 王正军 编著
- 最新章:第136章
- SQL 21日自学通(V3.0)(PDF格式)
- -Page 1-SQL 21 日自学通(V1.0 翻译人 笨猪目录目录 1译者的话 14第一周概貌 16从这里开始 16
- 最新章:第170章
- 2008年青年文摘精编版
- 作者:中国青年出版社“初恋”的惩罚.作者:凡 凡 文章来源《真情》2005年第4期 点击数:6608 更新时间:2005-6-5过了年,我就十八岁了。离高考只剩下四个多月了。这一段,班里的男女生相互间递纸条、写情书、约会等地下活动慢慢的多了起来。我这个“尖子生”也突然感到了不安、慌乱,并且自责。不知
- 最新章:第230章
- JMS简明教程(PDF格式)
- -Page 1-JMS1.1规范中文版卫建军2007‐11‐22-Page 2
- 最新章:第28章
- SQL语言艺术(PDF格式)
- -Page 1-SQLSSQQLL语言艺术内容介绍本书分为12章,每一章包含许多原则或准则,并通过举例的方式对原则进行解释说明。这些例子大多来自于实际案例,对九种SQL经典查询场景以及其性能影响讨论,非常便于实践,为你数据库应用维护人员阅读。资深 SQL 专家 Stéphane Faroult倾力打
- 最新章:第27章