现在的位置: 首页 > 综合 > 正文

Effective C# 第三章,用C#表达你的设计(译)

2013年06月18日 ⁄ 综合 ⁄ 共 2256字 ⁄ 字号 评论关闭

第三章,用C#表达你的设计
Chapter 3. Expressing Designs with C#

C#语言为你的设计介绍了一种新的语法,你可以选择这种技术让你的设计与其它的开发人员进行交流,这些开发人员可以维护,扩展或者是使用你设计的软件。C#的所有类型都是生存在.Net环境下的,这个环境对于所有类型的兼容性做了一些好的假设。但如果你违反了这些假设,你就增加了类型不能正确工作的可能性。

这些原则不是那些已经出版了的软件设计技术的概要,相反,这些原则醒目的给出了怎样用不同的C#语言特性来表达最好的软件设计意图。C#语言的设计者添加了一些语言特性,用来更清楚的表达现代的软件设计习惯。具体的语言特性有什么杰出的地方是很微妙的,并且你经常会有很多可选的方法。更多的选择在一开始可能只是更好的方案,但随后,语言特性杰出的地方会展示出来,你会发现你有必要增强已经存在的程序。确保你能很好的理解这些原则,并且小心的应用它们,在你创建自己的系统时,注意那些最有可能增强(设计)的机会。

一些语法的改变会给你一些新的词汇,用来描述一些你每天都要使用的习惯。属性,索引器,事件,以及代理就是例子。它们与类和接口是不同的:类定义类型,接口声明行为。基类声明类型,并且为一些放在一起的相关类型定义一些常用的行为。因为垃圾回收器,另一些设计习惯已也经改变了;还有一些改变,是因为大多数变量是引用类型。

这一章里推荐的原则会帮助你为你的设计选择一些最自然的表达方法。这将让你能设计出更容易维护,更容易扩展,并且更容易使用的软件。
==============
   

Chapter 3. Expressing Designs with C#
The C# language introduced new syntax to describe your designs. The techniques you choose communicate your design intent to the developers who maintain, extend, or use the software you develop. C# types all live inside the .NET environment. The environment makes some assumptions about the capabilities of all types as well. If you violate those assumptions, you increase the likelihood that your types won't function correctly.

These items are not a compendium of software design techniquesentire volumes have been written about software design. Instead, these items highlight how different C# language features can best express the intent of your software design. The C# language designers added language features to more clearly express modern design idioms. The distinctions among certain language features are subtle, and you often have many alternatives to choose from. More than one alternative might seem "best" at first; the distinctions show up only later, when you find that you must enhance an existing program. Make sure you understand these items well, and apply them carefully with an eye toward the most likely enhancements to the systems you are building.

Some syntax changes give you new vocabulary to describe the idioms you use everyday. Properties, indexers, events, and delegates are examples, as is the difference between classes and interfaces: Classes define types. Interfaces declare behavior. Base classes declare types and define common behavior for a related set of types. Other design idioms have changed because of the garbage collector. Still others have changed because most variables are reference types.

The recommendations in this chapter will help you pick the most natural expression for your designs. This will enable you to create software that is easier to maintain, easier to extend, and easier to use.
 

抱歉!评论已关闭.