with two implementations。 If not; use text streams。
o When streaming data; it is best to customize as little as possible。 Doing so will pli
cate your program; and potentially introduce errors where none should exist。
o It is important that you understand the concept of marshaling and the fact that each
medium will have a different representation of the type。 A large part of your programming
day will involve moving data from one stream to another。
Some Things for You to Do
The following are some exercises to apply what you learned in this chapter。
1。 In the implementation of TextProcessor; the display help routine was not very helpful。
Fix the implementation。
2。 There were no testing routines for TextProcessor。 Devise some realistic tests。 By realistic
tests; I mean tests that don’t just focus on the class library and consider the application
tested。 Focus on plete application tests。
3。 Having implemented the display help routine; think about whether or not the imple
mentation is correct。 The class Bootstrap is a general class that uses an IProcessor
instance; which means that different console applications will process different data。
Thus; writing a general help output might work; but it will not help in resolving problems。
Fix the console application TextProcessor and ReaderWriter project so that the help
message is both specific and general。
4。 In the Bootstrap class; when the output was redirected to a file (as indicated by the …out
argument); there was no check on whether or not the file exists。 Extend the Bootstrap
class to include an additional mand…line argument that verifies if it is fine to overwrite
the output file if it exists。 If an output file does exist and there is no explicit overwriting;
generate an error and stop processing。
5。 The code in the final solution for IProcessor。Process() has been identified as being hard
to maintain because the code to check for duplicate dates is scattered throughout the
method。 Rewrite the method implementation so that the code is logical and maintainable。
…………………………………………………………Page 307……………………………………………………………
C H A P T E R 1 1
■ ■ ■
Learning About Generics
Chapter 9 explained how to use lists; delegates; and lambda expressions。 In that chapter; you
also saw an example of generics when using lists to manage a collection of object instances。
The main focus of this chapter is generics and how to use them in a black box context
(the code doesn’t know the specifics of the generics parameter types)。 The secondary
focus is an implementation of lambda expressions using a spreadsheet。 The idea is to get you
well versed in generics and lambda expressions; which you will likely use in your own
production code; so that that there will be no surprises in your projects。
Why Use Generics?
Here’s a surprise for you: there is no imperative need for generics; so you could skip this
chapter and read the next one; right? Wrong。 I could just as easily have said there is no need for
Visual Basic properties; nor any other Visual Basic construct that enriches your programming
abilities。 The reasons we have Visual Basic properties and generics are programming
elegance and expressiveness。
To understand what I am trying to get at; consider this sentence:
Ducks walk flat feet quack loud
Reading the sentence; you get an idea of what is being said; but you are not pletely
sure。 Visual Basic without generics is like this sentence; in that you express your ideas in
code; but some things are not as clear as you would like。
Visual Basic with generics is like this sentence:
Ducks walk in a funny manner due to their flat feet; and when they quack; it is very
loud。
The sentence is clearer and uses more words to describe the same thing。 The reason we
talk using a more sophisticated language is that we want to explain concepts and be under
stood。 If you accept that; then you can accept why there is a need and context for generics。
And if not; feel free to skip this chapter and read the next one。
An example that illustrates how using generics makes your code clearer; as well as
more concise; than code that does not use generics is a container。 A container is a type
that is used to manage other types; lists and collections are examples of containers。 To keep
285
…………………………………………………………Page 308……………………………………………………………
286 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
things simple; let’s look at a container that manages a single reference。 The following is the less
concise version that uses the Object type。
Public Class Container
Private _managed As Object
Public Sub New(ByVal toManage As Object)
_managed = toManage
End Sub
Public ReadOnly Property Managed() As Object
Get
Return _managed
End Get
End Property
End Class
In the code; the class Container has a constructor with a parameter and a single property;
Managed; which references the variable _managed。 The idea beh
小说推荐
- 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章