Effective C# 第三章,用C#表達你的設計(譯)

來源:互聯網
上載者:User

第三章,用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.
 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.