Techbubbles

Guidelines for Developing Class Libraries in .NET

This post explains about design guidelines for developing class libraries that extends the .NET Framework. Following design guidelines provides benefits of consistency and unified programming model for developers.

Naming Conventions for Casing Identifiers

There are two different styles in Casing Identifiers

  • Pascal Casing – The first letter in the identifier and first letter of subsequent  word are capitalized.  DateOfBirrh

Use Pascal Casing for following types

    1. Public member
    2. Type
    3. Namespace

Examples:

Type Case Example
Class Pascal WorkItem
Enumeration Type Pascal LogLevel
Event Pascal ValueChanged
Read Only field Pascal RoleValue
Interface Pascal IProduct
Method Pascal ToString
Namespace Pascal System.Web
Property Pascal EmpName

for the two character acronyms, capitalize the both characters in the word

Example: DBRate

If the acronym contains more that three characters then capitalize first character of word

Example: XmlWriter

  • Camel Casing – The first letter of an identifier is lowercase and first letter of subsequent word are capitalized. dateOfBirth 

Use Camel Casing for parameter names

Parameter Camel typeName

If the parameter contains more than three characters in acronym then use following style

        htmlReader

  • Upper Case – All letters in the identifier are capitalized. IO

Guidelines for Naming types and members in Class Names

  1. Use readable names for elements in the class library.
  2. Do not use underscores or special characters
  3. Do not use Hungarian notation – it is a method of using data types as prefix for identifier names.
  4. Avoid using keyword names for your identifiers

Guidelines for Naming Namespaces

The namespace name should represent the functionality made available by types in the namespace. For example System.Web contains type that enables browser\server communication.

General Format for NameSpace is

<ComapanyName>.(<Product>|<Technology>)[.<Feature>][.<subnamespace>]

1. Use Plural namespace names wherever necessary

2. Do not use the same name for a namespace and a type in that namespace

Guidelines for Classes, Structs and Interfaces

In General type names are noun phrases, choose names that identify entity from developer perspective.

  1. Do not give class names a prefix such as C
  2. End the name of the derived class with the name of the base class
  3. Prefix the interface names with letter I
  4. Consider using letter T for generic type parameters example: IDictionary<Tkey,Tvalue>
  5. Add suffix Exception to types that inherit from System.Exception
  6. Do not add the suffix Delegate to a delegate
  7. Add suffix Stream to the types that inherit from System.IO.Stream

Guidelines for Type Members

Types can contain the following kinds of members:

  • Methods
  • Properties
  • Fields
  • Events

Give verb phrase for method names. Verb can describe the action of method makes it easier for developers to understand what the method does.

  1. Use Noun phrases for giving property names.
  2. Name EventHandlers with the event handler suffix
  3. Name event argument classes with the EventArgs suffix
  4. Use Pascal case for naming the field names
  5. Do not use any prefix for field names

Please follow the link for detailed guidelines for designing class libraries

Share this post :

3
Leave a Reply

avatar
2 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
ManikandanKalyan Bandarupallisuresh Recent comment authors
  Subscribe  
Notify of
suresh
Guest
suresh

Good One! Liked the jist of all guide lines.
Explaination of technical reasons for some of the guidlines should been included!!!

Manikandan
Guest
Manikandan

Thanks lot for valuable ideas