additional rules regarding grammar。 When using generics; you need to master creating abstractions。
generics are an abstraction。 Just as interfaces are an abstraction of classes; generics are an
abstraction above interfaces。 Interfaces define an intention; and generics define an abstract implemen
tation of an intention。
What is challenging with generics is getting your thoughts together into an abstract intention
implementation。 It is like writing a document—you write it once; read it over; rewrite it; read it over; and
rewrite it again。 With generics; you are gathering thoughts together into a general plan of action。 This
is why some people are pletely confused and don’t understand generics。 Writing your own
generics code requires some forethought。
The Theory of a Server…Side Spreadsheet
The example in this chapter is a spreadsheet for security traders。 When you trade securities—
whether they are equities; bonds; options; or futures—you will be confronted with information
overload。 You might have seen pictures of traders with desks full of desktop monitors。 A trader
might have seven to eight monitors displaying various bits of information。 A trader is a very
specialized type of domain that requires its own ways of processing information。 One aspect
that makes writing applications for traders difficult is that the nature of the data constantly
changes; and types get more in the way than they help。 As a result; traders adore spreadsheets。
Spreadsheets are useful because they can process large amounts of information in a relatively
ad hoc manner。 However; one downside to spreadsheets is that the processing time can
…………………………………………………………Page 311……………………………………………………………
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 289
dramatically increase due to the constant pushing and pulling of the data to and from the
spreadsheet。 To speed up processing; we will define and implement a spreadsheet that has the
advantages of a traditional client…side spreadsheet。
■Note The theory and solution presented here are specific to the domain of trading; where the cost of hard
ware is well worth the ability to trade properly。 Therefore; specific design aspects assume that you have the
latest and greatest hardware。
An initial attempt at a spreadsheet would be the following code that uses generics:
Class Spreadsheet
Public Cells As Func(Of Object)(;)
Public State As Object(;)
Public Sub New()
Cells = New Func(Of Object)(10; 10) {}
State = New Object(10; 10) {}
End Sub
Public Sub Execute()
For col As Integer = 0 To Cells。GetLength(1) 1
For row As Integer = 0 To Cells。GetLength(0) 1
Console。WriteLine(col & 〃 〃 & 〃 〃 & row)
If Cells(row; col) IsNot Nothing Then
State(row; col) = Cells(row; col)()
End If
Next
Next
End Sub
End Class
The sample spreadsheet is defined using the data members Cells and State。 Both data
members are arrays with two dimensions。 The first dimension represents the rows; and the
second dimension represents the columns。 You could define as many dimensions as you wish;
but for the scope of the server spreadsheet; we take a two…dimensional approach。
The Execute() method goes through the individual rows and columns of the Cells data
member; calculates the state of the cell; and assigns the state to the State data member。 The
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
小说推荐
- 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章