Learn About a 3-Layer Model

Tram Ho

  • Since I have been working on some desktop apps recently using a 3-layer model, I will note what needs to be noted in the 3-layer model.

1. What is a 3-layer model?


  • The 3-layer model, also known as the Three Layer (3-Layer) model, was created to divide the components of the system, the components with the same functions will be grouped together and divided into tasks. for each group so that data doesn’t overlap and run wildly.
  • This model works best when you build a large system, making it easier to manage code and handle error data.


  • Clearly classify classes for different tasks. From there we can better manage and maintain the project.
  • Easily classify actions at Business.
  • Easily classify functions accessible in Database, sort functions by table, etc.
  • The application is for large external projects.

Note when building a 3-layer model:

  • Need a separate solution for the project.
  • Need 3 different projects to make 3 classes, the Project name is as follows:
  • GUI layer: (Example: QuanLy_GUI)
  • Business Class: (Example: QuanLy_BUS)
  • Data Access Class: (Example: QuanLy_DAL)
  • DTO Class: (Example: QuanLy_DTO)

2. Introduction of the 3-layer model

3-layer model consists of 3 main parts:

Presentation Layer (GUI)

  • This class has the main task of communicating with users. It consists of interface components (winform, webform, …) and performs tasks such as inputting, displaying data, checking data accuracy before calling Business Logic Layer (BLL).

Business Logic Layer (BLL) This layer is divided into 2 tasks:

  • This is the place to meet the data manipulation requirements of the GUI layer, processing the data source from the Presentation Layer before passing it to the Data Access Layer and saving it to the database management system.
  • This is also a place to check data constraints, integrity and validity, perform calculations and process business requirements, before returning results to the Presentation Layer.

Data Access Layer (DAL)

  • This class has the function of communicating with the database management system such as performing tasks related to storing and querying data (searching, adding, deleting, modifying, …).

3. The composition of each class

Presentation Layer (GUI)

There are two main components to specific tasks:

  • UI Components : includes components that make up the application’s interface (GUI). They are responsible for receiving and displaying data to users … For example: textbox, button, combobox, …
  • UI Process Components : is the component responsible for managing the conversion process between the UI … For example: Arranging the process of checking customer information:
    1. Display ID lookup screen.
    2. Display the corresponding customer details screen.
    3. Display customer contact screen.

Bussiness Layer (BLL)

This class consists of 4 components:

  • Service Interface : is a programming interface component that this class provides for Presentation class to use.
  • Bussiness Workflows : responsible for identifying and coordinating multi-step and lengthy business processes. These procedures must be arranged and performed in an exact order.
  • Business Components : responsible for checking business rules, binding logic and performing tasks. These components also implement the services that Service Interface provides and Business Workflows will use it.
  • Business Entities : commonly used as Data Transfer Objects (DTO). You can use this to transfer data between layers (Presentation and Data Layer). They are usually data structures (DataSets, XML, etc.) or customized object classes. For example, create a Student class that stores data on name, date of birth, ID, class.

Data Layer (DAL)

  • Data Access Logic Components : responsible for storing and accessing data from data sources (Data Sources) such as XML, file system, … Moreover, it also facilitates easy configuration and maintenance. Service Agents: help you call and interact with services from outside easily and simply.

Để hiểu rõ hơn về cấu trúc và cách xây dựng của mô hình 3 lớp, chúng ta cùng tham khảo một ví dụ về mô hình quản lí Uber gồm các lớp BUS, DAO, DTO, GUI ( Lớp GUI sẽ là phần chương trình chính).

Because I’m lazy here, so I put them into folders to easily call each other: v (If done properly, it must be created projects in the new Solution)

  • The first is the GUI including buttons, texbox, … that users will interact with this interface screen.

  • DTO class, containing the data built as object class. Each User will have the following properties:

The main processing operations will be placed at the BUS layer (or BLL) including insert, update, delete, etc.

And finally DAO class (or DAL). Query to the database

So I have finished simulating how to structure a program using a 3-layer model. If there are errors, I hope everyone would like to comment. Thank you for reading this article.

Share the news now

Source : Viblo