Depth. NET platform for Software system development (1/6)

Source: Internet
Author: User

Chapter One hierarchical development of software systems

1.1 Partitioning architecture

Split into schema definitions: implement different modules in the solution into different projects. The primary key in each layer should remain cohesive, and each layer should be loosely coupled with each layer below him.

Layered mode is one of the most common architectural patterns, and even a partitioning pattern is the basis of many layered patterns.

Data access layer: At the lowest level, responsible for interacting with the database and becoming the DAL (data Access layer).

Presentation layer: Deals directly with the user, is responsible for displaying or fetching data, also known as the UI layer (user Interface layer). Displaying data using the console or Windows Forms is an application of the presentation layer.

The presentation layer relies on the data access layer, separating the two layers of functions, working together, as shown in dependency 1.4

1.2 Building a layered architecture

1.2.1 Assembly

Assembly Definition: If you run the MySchool program, a MySchool.exe file will be generated in the Bin\Debug directory, and you can open the MySchool application by double-clicking the file. This compiled. exe file belongs to the assembly.

. NET assembly is the basic construct of any. NET Framework application. An assembly consists of the assembly manifest that describes it (including the version number, assembly name, and so on), the type metadata, the MSIL code, and the resources, which are distributed in a folder, or in several folders, asshown in 1.5:


      • Executable file, or. exe file.
      • Class library file, or. dll file.
      • A solution can consist of one or more projects, which can be Windows applications, class libraries, and so on.
      • Namespaces are a logical schema for an organization's C # program, and a namespace can have multiple classes.

1.2.2 How to create a layered schema

(1) Add a class library to the project. By right-clicking the solution and choosing Add > New Project from the shortcut menu that pops up, the Add New Item dialog box pops up and the new item is named "Myschool.bal".

(2) Add a dependency between the presentation layer and the data access layer. Both the presentation layer and the data access layer are established, but each layer is independent, and there is no dependency between them, and there must be a dependency between them to be used as a whole, that is, to establish a dependency presentation layer for the presentation layer and the data access layer to invoke the classes in the latter. There are two ways to form a dependency.

The first way is to right-click the MySchool item and Add Reference in the shortcut menu that pops up.

The second option is to select the Browse command to add a reference to the data access layer to generate the. dll file.

1.3 Benefits and benefits of tiered development

    • Code reuse
    • Separation of concerns from developers
    • Lossless replacement
    • Reduced dependency between systems

1.4 Exception Handling

1.4.1 Why do you want to handle exception

The Hierarchical architecture development system is described earlier, but the failure between the various layers of the system is unavoidable. If the application of the user's operation to check, to determine that the disease in the event of failure is a hint of error or appropriate processing, will be as far as possible to avoid the crash of the program system, which uses the exception handling.

In C #, a program runs in error through an "exception"

Mechanism is propagated in the program. An "exception" is an error that occurs when a program executes, and the cause of this error comes from three aspects.

    1. Code error: Includes compile error, only caused by developer.
    2. Resource Not available: An error caused by the system accessing an unauthorized resource.
    3. Common language Runtime: errors caused by internal CLR.

1.4.2. NET exception handling mechanism

The exception is represented by a derived class of exception. There are two cases in which exception handling is encapsulated in the exception class.

    • An exception that is thrown by the user program execution, derived from the ApplicationException class.
    • Exceptions thrown by the common language runtime, derived from the SystemException class.

Common exception types

Common Properties for exception classes

Exception Handling Statements

Syntax:1.Try-CatchTry{        //work code that could throw an exception}Catch(Exception object) {//Exception Handling}2.Try-finallyTry{      //The work code of the exception that may be thrown}finally{       //clean up related object code}    3.Try-Catch-finallyTry{        //work code that could throw an exception}Catch(Exception object) {//Exception Handling}finally{       //clean up related object code}

Multi-path anomaly capture

Try {        // work code that could throw an exception }catch(Exception ex) {       thow ex;} Catch (SqlException ex) {       thow ex;}

Depth. NET platform for Software system development (1/6)

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.