Application DesignNaming and Code Specification

xiaoxiao2021-03-06  16

Architecture specification

Overall design

The architecture of the .NET Web Forms application should follow the Microsoft proposed architectural solution. According to the size of the project, each basic level is appropriate. The purpose of dividing the system into multi-layers is to simplify the internal logic of individual subsystems. Based on the following rules create:

At least there should be at least a layer and business

The application should generally be divided into: representing the layer, the business logic layer, and the data is accessed.

If the business process is more complicated, the business rules layer should be added

Data entities should be implemented for basic business objects in business (usually DataSet expansion)

Store procedure operation database should be used separately

If you need a basic component (global parameter configuration, exception handling, log) that is not related to your business, you should include the application framework layer (System Framework)

If you contain Custom Controls, you should be separate as a Project.

The figure above is a system architecture for the sample application DUWAMISH 7.0 provided by Visual Sudio.NET. Participation in critical data flow is the web, business façade, business rules, data access. The image image shows the call relationship between the layers.

Representation layer (ASP.NET) design

In the entire solution, only the representation contains an ASPX file, an ASP.NET technology. Represents the task of the layer to display the data to the user in a certain format, and can accept the data entered by the user, and process the user's operation. Representation layer by the Web Forms page, User Control, and Code Behide make up, generally contain other resource files required. Design and architecture should follow the following principles:

1. In order to maximize the page composition design, the main public elements of the page should be built to ASCX.

2. The main logic module should be built in the same ASCX. For example, the process of user registration. By independent, embedded to the page, the module is handled by the logic. The benefits of doing this are to isolate presentations logic and business logic.

3. The ASPX page is just a small amount of basic HTML, and the basic page composition is expressed. Code Behind only operates the display and hide of the ASCX. Does not include business logic

4. You should extend from system.web.ui.controls.webcontrols.page with System.Web.ui.Controls.WebControls.userControl. All ASPXs and ASCX are extended in this layer. The base category should include basic information such as safety information, user status.

5. ASPX should capture the user events of the loaded controls. User events generally represent various phases of the ASCX life cycle. For example, the control is initialized, the operation is canceled, the operation is complete, and the operation is aborted.

6. When presenting the collection of data, try to use the Repeater as much as possible.

Data entity design

Data entities are the core business objects processed by the system. Take an e-commerce application, the core business object is the goods, supplies, customers, orders. Data entities are generally DataSet. Each DataSet is forced to define a table, column, and memory databases that are constrained, and constraints. The definition of the table structure is that the actual data can be different from the database. The data transmitted between each layer is a simple DataSet. This can be completely unified in the interface of the external development. For example, when the user requested that all types of items are queried, the data layer can fill the result into an entity in advance.

Business layer design

The business layer is directly served in the representation layer. Provide the required data for the representation layer. Processing the operational requirements of the layer. In fact, the role of the business layer is a mediation representing the layer and the data access layer. The demand of the representation is parsed to the data operation of the data layer. This applies the FACADE design mode. That is to provide a unified interface to the subsystem to simplify the operation. In the actual design. Generally designed the class of the business layer as the center of the various core subsystems. It can reduce the coupling between system hierarchies. Improve flexibility.

Data layer design

Databases are done directly. Needly should not contain any business logic. A good data layer design should only contain basic operations such as read and write deletions. Provide data required for the business layer.

Naming conventions

Size

The project should be scheduled to arrange a vocabulary. Developing members choose the vocabulary to select accurate vocabulary in accordance with the vocabulary. To achieve a unified purpose. The following rules indicate the following identifiers according to the style recommended by the MSDN:

IdentifierCaseExampleClassPascalAppDomainEnum typePascalErrorLevelEnum valuesPascalFatalErrorEventPascalValueChangeException classPascalWebException Note Always ends with the suffix Exception.Read-only Static fieldPascalRedValueInterfacePascalIDisposable Note Always begins with the prefix I.MethodPascalToStringNamespacePascalSystem.DrawingParameterCameltypeNamePropertyPascalBackColorProtected instance fieldCamelredValue Note Rarely used. A property is preferable to using a protected instance field.Public instance fieldPascalRedValue Note Rarely Used. a Property is preferable to using a public instance field.

Size sensitive settings

Since the .NET platform is a cross-language operation, it requires applicable for language-sensitive language and case sensitive languages, so it is absolutely unable to use only the sizes that rely on case-by-case recognition.

Abbreviation form

1. No shorthand or abbreviations for English words are not allowed. For example, getWindow is written into getwin.

2. The abbreviation form of the provincial devilion is not allowed. For example, write the Message into an MSG.

3. Not allowing the use of only the clocked words that have not been widely used.

4. Use the conventionally known first letter abbreviation instead of longer names. For example, gethtml.

5. The abbreviations should be used as a word, ie the form of other letters lowercase, such as SQL Server.

6. If the abbreviation word has only two characters. It should be all capitalized. For example, System.Web.ui.

General rules should be observed

1. Must use the correct English words. Chinese pinyin or any other form of abbreviation is not allowed.

2. Vocabulary must be complete. No shorthand form is not allowed. For example, it is not allowed to write Message into an MSG.

3. If the name represents a plurality of meanings, it should use its correct plural form.

4. The conventional alphabetic abbreviation can be used as a word.

5. Try to describe the meaning of the signature. That is, an element is used to represent one or more words.

Circumvent

Avoid using the vocabulary of .NET Namespace. Avoid using vocabulary conflicts with keywords:

Keywords list:

AddHandler Addressof ALIAS and ANSI

As assembly auto base boolean

Byref byte byval CALL CASE

Catch CBool ​​Cbyte Cchar Cdate

CDEC CDBL CHAR CINT CLASS

CLNG COBJ Const Cshort CSNG

CSTR CTYPE DATE DECIMAL DECLARE

Default delegate Dim Do Double

EACH ELSE ELSEIF END ENUM

ERASE Error Event EXTERNALSOURCE

False Finalize Finally Float for

Friend Function GET GETTYPE GOTO

Handles IF IMPLEMENTS IMPORTS ININHERITS INTEGER INTERFACE IS Let

LIB LIKE Long

Loop ME

Mod Module Mustinherit Mustoverride Mybase

Myclass Namespace New Next NOT

Nothing Notinheritable NotOverridable Object On

Option Optional or Overloads overridable

Overrides Paramarray Preserve Private Property

Protected Public Raiseevent Readonly Redim

Region Rem RemoveHandler Resume Return

Select Set Shadows Shared Short

Single Static Step Stop String

Structure Sub Synclock THROW

To True Try TypeOf Unicode

Until Volatile When While with

WitHevents Writeonly Xor Eval Extends

Instanceof package var

File name, file directory name

1. All word first letters are closely up. The first word must also be capitalized. Only one word must also be capitalized. Underline connection is not allowed. Numbers are generally not allowed in clear. (Except for special circumstances)

2. The extension must be lowercase.

3. Application default homepage must be default.aspx.

4. Allows the use of modified noun phrases, verbs - the signature of the name of the noun to represent the ASPX file name. (For example, the memberdetails.aspx) ASPX file name must be accurately used. Use the appropriate single reputation form and verb timing form.

Namespace named

Name Namespace in the following form:

CompanyName.technologyName [.feature] [. Design]

Pascal form

The name of the solution should be used to start with the name of the development.

If you sell as a product, you should start with the company brand.

The same solution should be written in the same top nameSpace as much as possible.

Each item should set a secondary namespace. Take the project name.

If the noun has a plurality of meanings, its plural form should be used. For example, Nestle.Web.userControls.

Namespace and classes are not allowed.

Class name

1. You must use a PASCAL form

2. Class name checklists must fully accurately indicate their meaning. Words are not allowed to use. Also avoid the meaning of the meaning of too widely and more prone to discrimagination. For example, it means that the vehicle should use Vehicles without choosing CARS. Employees should use Employees, without choosing Personels. In general, the choice of vocabulary must be fully discussed before the project, listing the vocabulary. Members should strictly abide by the word rules. Avoid the same significance to use two different vocabulary.

3. Must use noun or noun compound words, if only verb meanings, use its subject form. For example, Importor.

4. Careful use of abbreviations

5. Do not allow the prefix indicating the data type.

6. Underline connection is not allowed

7. Use a compound word to represent the school class. For example, the class derived from the LinkButton can be named submitLink. Any DataAccessException.

8. The interface is typically prefixed with i. And the second letter is capitalized.

9. Use the same vocabulary to represent interfaces and related classes such as:

Public interface iComponent

{

}

Public class company: iComponent {

}

Method naming

1. Use the verbs - nouns to name routines to perform specific operations for a given object, such as CalculateInvoiceTotal (), Removeall (), getchararray (), invoke ()

2. The method name must be able to describe its meaning in detail.

Property named

1. Use nouns or noun compounds.

2. It should be used in the form of multiplexes.

3. Do not be the same as its data type

4. In the object-oriented language, the name is redundant in the name of the class properties, such as book.booktitle. But you should use book.title.

5. Boolean attributes should contain IS, which means yes / no or true / false, such as IsFileFound.

6. Use #region to define all Property to organize together. To manage the source code.

7. The comment must begin with "public characteristics:"

8. If there is a default value, you will directly assign a value to the relevant private member variable.

Event naming

1. Use the EventHandler suffix to identify the event processor.

2. Typically specify both Sender and E two parameters. The Sender type is always Object. The EXCEPTION type is the same as the event.

3. Use the verbs to indicate events. For example, a composite structure consisting of clamps, or noun verbs. For example, Taskabort.

4. Using the time indicator indicating that the event is used to indicate the incident, such as Taskaborting and Taskaborted.

Web control named

1. You must use the meaningful name to represent the web control used.

2. The control must be able to explain its own type. For example, a LinkButton type control, its ID must be ended in LINK. The following is the corresponding relationship between the basic control type and the suffix:

a) LinkButton Link Example: SaveInformationLink

b) TEXTBOX BOX Example: UserNameBox

c) DROPDOWNLIST LIST Example: Localelist

D) Label Label Example: BirthDateLabel

e) Panel Panel Example: DetailFormPanel

f) REPEATER REPEATER: TaskRepeater

g) The rest can be pushed according to the rules

Database named

1. Table name, column name will only allow lowercase. It is strictly forbidden to use the size of the database named

2. Use the correct and complete form of common English vocabulary, any form of abbreviation or shorthance should not be allowed.

3. When connecting multiple words, use underscores

4. The table name has a plurality of meanings, using the correct plural form of the noun.

5. Under normal circumstances. Column names should not contain any forms of the table name or table name. The column name is not allowed to use a unified prefix.

6. Key data object table uses a single noun. To distinguish, non-critical data object forms will use composite names. For example, MEMBERS, Member_Messages .7. Dictionary table (using Table only to indicate the index and the name corresponding to the relationship) The prefix starts. And use the singular form of the noun. For example INFR_LOCALE (geographical index table)

8. Dictionary table primary key will use the index_id name (lowercase) and is a Varchar type.

9. The base non-critical table must contain an automatic increase type INT primary key, and the name must be a PKID (Primary Key ID). For example, log in to the log of the log in to the log.

10. View naming, should end with the _View ternary.

11. Do not allow the SP_ prefix to be added to the stored procedure. (SP_ prefix is ​​a system stored procedure.) The stored procedure should be verb-noun domain. And habitually start with INSERT_, UPDATE_, SELECT_, DELETE_.

Coding Standards

C # code

It is very important to maintain a good coding specification in development. Coding specifications and agreements must significantly improve code readability and help code management, classification.

1. You must use intelligent indentation code. And the tabs and moisture sizes are 4 characters. Insert space is not allowed to indent. (Use the default settings for Visual Studio.net).

2. It must be vertically left and right in the code. No left and right parentheses are written on one line.

3. Only one statement can only be accommodated in the same line.

4. When the content is too long, the retransmission format is used in the back line, as follows: String Inserstring = "Insert Into Tablename (Username, Password, Email, SEX, Address"

5. Recommend each row of statements to start with this code assistant. Accelerate writing efficiency and accuracy.

6. Try not to put a longer statement to improve readability. (Experience proves that it will bring difficulty in reading and maintenance of an indivisible statement.)

Code organizational structure

Code organizational structure

Code organizational structure

Code organizational structure

Code organizational structure

1. Adopting the code in the order of organizational classes: Class Description (Note) Name This Space Declaration Using Statement Group Category Description Class Declaration Private Variable Public Attributes Declaration

2. Public attributes and corresponding private variables must be written together. And comment comments, such as: ///

// / public characteristic: Resource file (image file and scripting resource) Reference path / / / The address of the application root path, can not end ////////////////////////////> PRING ResourcePathpublic String ResourcePath {...}

Code behidn organizational structure

1. Adopt code in the order of organizational classes: Class Description (Note) Using statement group name Space declaration class Description class declaration ASPX Used ASPX Standard Controls ASPX Used User Control Private Variables Private Void Page_Load (Object Sender, System.Eventargs E) Method Realizes the generation of #REGION web form designer generated: Override Protected Void OnNit (Eventargs E) Custom Event Process: Method Definition

2. Note A custom event handling method must indicate the scene when the event is triggered. For example, "Check the Heavy Name"! Event Process, where the vocabulary referenced by the double quotation number and the exclamation mark is the control performance seen by the front desk. Usually a button or A link for text. Can be further explained in one visit.

Dark line and space

1. Leave a holiday before the class definition, method definition, the public property definition

1. Leave a blank line before the logical code segment

2. Leave a nicker after comma

3. There is a space before and after the operator. But except for the FOR cycle of the short words. (Leave a space only after the semicolon) 4. Do not allow excess blank lines and spaces.

5. Do not leave space between GET and SET processes defined public attributes

Comment

1. When comment, the Visual Studio IDE C # editor will automatically generate /// Help to generate standard XML annotations, must be used when comment module, class, important feature, method, and line Inter-comment cannot be used

2. Note The full Chinese statement statement must be used. Avoid comments to produce polymity and more difficult to understand.

3. Avoid extra or inappropriate annotations. Or humorous can have no comments.

4. Writes must be used in the comments. Avoid using spoken or informal wording. Note Do not have an object or extra tone words.

5. Note The tag symbol for use in English must be used in English.

6. Not allowed to mark comments with a whole line number or slash.

7. Module Note: Written on the .cs file. Branch indicates the module name, meaning and function, the author, the author, the modified person must indicate the name and time of the modification. The above must be all used in Chinese. Date format

2004-2-29 format indicates 24 hours, accurate to minutes.

8. Class Note: Writing is written on the class definition. Description Main function. Algorithm and precautions are used.

9. Die Note: Start with double slash. It must be a commented code. It is necessary to next to the code line. Xu is increasing in the end. This situation except for the multi-line code, respectively.

10. In the comment, if there is a Chinese and English mix, you should pay attention to the use of appropriate cases. If English is displayed, all lowercase is used. (Except for special nouns, organizations, corporate names, and abbreviations.) If there is a proprietary noun consisting of multiple words, each word first letter is capitalized. Such as Microsoft Internet Explorer.

T-SQL programming

1. SQL Text Command Keywords must all be used in uppercase.

2. The database naming involved is strictly used in its original form.

转载请注明原文地址:https://www.9cbs.com/read-41484.html

New Post(0)