. NET design specification One: The basis of design specification

Source: Internet
Author: User

Http://www.cnblogs.com/yangcaogui/archive/2012/04/18/2447049.html

Read it some time ago. " NET Design Specification "This book, read to me after the feeling is the norm for developers have a pivotal importance, maybe we all have their own ideas, but I believe that follow these predecessors to summarize the norms will bring benefits to our development, so familiar with these development norms and develop good habits is required we insist, Slowly these norms will affect US imperceptibly!

  1.80/20 Principles

The so-called 80/20 principle, in some special cases, to pay attention to the "20%" part, "80%" part can reduce the importance of, in fact, most of us know there is such a principle, but I have not really put this principle into practice, if you use this principle to examine some large projects , there will be a lot of design with a knife this principle, such as a period of time an article on "Baidu" and "Google" the paging problem, it is very good use of 80/20 this principle, well, not much to say, began the normative journey ...

2. Type Naming conventions

   2.1 Casing Specification

There are two types of nomenclature: ①pascalcasing → Pascal Nomenclature (the first letter of the word is capitalized)

camelCasing → Hump nomenclature (first letter lowercase)

Precautions:

① to use the "camelCasing" specification for parameters and the naming of variables

② do not use initials when naming, except for special cases such as →system.io

③ themain area used by "pascalcasing" is → illustration

        

    2.2 Type name Word selection

① to select an easy-to-read name for the name

② do not conflict with keywords in C #

③ do not use abbreviations and acronyms of words

④ do not use acronyms that are not yet popular

⑤ the words you choose to have meaning

    2.3 Namespaces

Specification: Simple to understand, and with generality

      

Specific specifications are as follows:

① use company name as prefix

② uses a stable, version-independent product name as the second layer of space!

③ use pascalcasing-case style!

④ consider the use of complex numbers in the appropriate name →system.collections

⑤ do not introduce too generic type names, such as Log,message, you should precede them with qualifiers!

Note: There are chapters in the book that introduce assemblies, but unfortunately I do not understand it very well, it is not written up!

    2.3 class, struct, interface naming

      Note: The type name should be a noun or noun phrase, and if you do not find a good noun or noun phrase for the type name, then you should consider re-designing the name!

Choose the name method: first you need to know what kind of scene you are designing, what the scene is for, and then choose the right noun or noun phrase to design!

such as: Stream,streamreader,textreader,stringreader this type of name design, or I want to design a JSON Operation class library, can be named →jsonoperation

Specific rules:

① is named with a noun or noun phrase and uses the "pascalcasing" case style!

② do not prefix any type name, which is taboo (except for the interface)!

③ consider letting the name of the derived class end with the name of the base class

For example: Exception, all of its derived classes end with the "Exception" base class name!

or "Attribute" or something.

Some of the derived class naming conventions in the. NET framework (detailed in the latter article will be covered), as shown in:

④ interface → with the letter "I" as the prefix, so that users at a glance, it is an old habit!

⑤ should make the type name of the implementation interface only one letter "I" from the interface name!

such as: interface ijsonoperation, the implementation of its class name should be → "jsonoperation"

    2.4 Naming of generic type parameters      

① to name generic type parameters with descriptive names as much as possible, prefix "T" before the word

      

② consider using "T" to name parameter types

If there is only one parameter type, such as →list<t>

③ if the generic parameter has a generic constraint, the type name of the constraint should be appended to the generic parameter

A type parameter that is limited to the ISession interface can be named → "tsession"

    

    2.5 Naming of enumerated types

① also to comply with the "pascalcasing" case specification

② to name enum types with singular nouns

③ to use a plural noun to represent the enumeration type of a bit mark (flags), such as:

1  [flags]2 public     enum Colors  //If it is a flag, it is recommended to use plural form 3     {4         read,5         black,6         Yellow7     }

④ do not add "enum" or "Flag" or "flags" suffix to the enumeration name, and do not add prefixes

    

Although very basic, but for our laymen have a pivotal role, work together!

. NET design specification One: The basis of design specification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.