gory was a type that implemented an interface (Implementation and IDefinition)。 The second
type was a class that subclassed another class ( LoaderSection; ConfigurationSection)。 Each
approach has its advantages and disadvantages; but there is a single rule that you can use。
Whether to use an interface or class depends on how much responsibility you want to
delegate to the implementation。 In the configuration processing example; the infrastructure
specifically indicated that the only responsibility of the dynamically loaded class is to indicate
which identifiers should be processed。 How the value of the identifiers are extracted and converted
into types is the responsibility of the base class。
When you instantiate a type and use an interface; you are delegating plete control to
the dynamically instantiated type。 The calling code is explicitly saying; “Here is your contract。
How you deal with it is your responsibility。 Just make sure to implement the contract properly。”
By delegating all the responsibility; you are; in a sense; asking for trouble; because developers
might implement a contract incorrectly。
The Important Stuff to Remember
In this chapter; you learned about configuring an application and dynamically loading code
that is executed。 The main items to remember are as follows:
o A application configuration file works only because there is code in the application
that uses the specified items in the configuration file。
o Applications have application configuration files where the name of the file is the
name of the executing application appended with a 。config。
o A application configuration file is a specially formatted XML file。
o A application configuration file applies to a specific assembly loaded by the
application。
o The default scenario for a application configuration file is to store the settings as
key/value pairs in the section。
…………………………………………………………Page 362……………………………………………………………
340 CH AP T E R 1 2 ■ L E A R N I N G A B OU T A PP L I CA TI O N CO N F I G U R AT IO N AN D D Y N A M I C L O AD I N G
o You can enhance the application configuration file; but that implies implementing
types that specifically outline which XML nodes and attributes are to be present in the XML。
o When processing data; you sometimes need a type (such as ConfigurationInfo) that is
used to store information in a structured manner for a specific reason。
o has plenty of functionality that allows a developer to dynamically execute code。
o One way of dynamically executing code is to load an assembly; instantiate a type; and
then cast the instance to a specific known type。
o You can instantiate private types declared in an assembly。
o You can use the GAC to store assemblies that will be shared by multiple applications。
o Use the GAC only if you must。 If you do use the GAC; you need to create strongly named
assemblies using signing。
o Regardless of how an assembly is versioned; a version number should exist and be used。
o In convention…based coding; your code makes assumptions about its behavior。
Convention…based coding is more pact; but because assumptions are made; the
code is less flexible。 However; do not confuse flexibility with being the best way to do
something。 You should have flexible code when you need it; not just because it can be
written that way。
Some Things for You to Do
The following are some exercises for you to do to apply what you’ve learned in this chapter。
1。 Rewrite the configuration code so that the configuration file specifies a directory where
all assemblies in that directory are loaded。
2。 Having read all of the assemblies with the rewritten configuration; call a predefined
type that will tell the caller which types are available and their appropriate types。
3。 Modify ConfigurationLoader so that it uses the new configuration architecture to
instantiate types。
…………………………………………………………Page 363……………………………………………………………
C H A P T E R 1 3
■ ■ ■
Learning About Multithreading
Your brain allows you to multitask。 For example; you can prepare dinner while talking on the
telephone。 However; this multitasking has limits; and you can do only two or three things
simultaneously。 But suppose you could put down the work; start another piece of work; then
put that down; and then switch to the original work。 How many tasks could you handle at the
same time? Probably a few hundred; because what you are doing is serializing the multitasking。
Now suppose you and another person are preparing dinner in the kitchen; but you are not
municating with each other。 What is the likelihood that you will run into the other person?
Probably pretty high。 What I am trying to get across here is the difference between multitasking
with a single brain and multitasking with multiple brains。 Multitasking always has a cost; which is
orchestration。 And sometimes doing more multitasking is not going to speed things up。 There
is a limit to how many brains are required to run an efficient kitchen。
The focus of this chapter is how to write code that is capable of multitasking。 The operating
system multitasks; by default; but whether or not your program multitasks depends on how
you write your code。 For example; suppose the lighting controller introduced in Chapter 8 had
to control 3;000 rooms?
小说推荐
- 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章