三层架构中的业务层

发布于 2024-12-06 01:48:11 字数 275 浏览 8 评论 0原文

我去参加面试,并被要求展示我的业务层架构。我对三层架构有一些想法,但真的不知道在面试官面前要写什么。 因此,假设我的项目涉及一个组织的员工,那么我会在那里写什么。它是我应该制作的任何类型的图表还是一些编码部分。我在 C# 框架 3.5 中工作。我真的不明白这个问题还需要提到什么,所以如果需要什么,请告诉我。谢谢。

编辑 我在 winform 中工作。 我知道什么是业务层,但是不知道该告诉面试官什么,因为业务层有代码,而且显然我的项目有点大,所以代码量很大。那么我应该在那里写什么?

I went for an interview, and was asked to show up my Business layer architecture. I have some idea about 3 tier architecture but really no idea, to what to write in front of interviewer.
So suppose my project deals with Employees of an organization, then what would i have written there. Will it be any kind of diagrams i should have made or some coding part. I worked in C# framework 3.5. I really don't understand what else to mention in this question, so please let me know if something is required.Thanks.

Edit
I worked in winforms.
I know what Business layer is, but was not sure what to tell the interviewer as business layer has codes and obviously my project was a bit big, so there were huge numbers of codes. So what i should have written there??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

弱骨蛰伏 2024-12-13 01:48:11

3 层架构由 3 个主要层组成

  • PL 表示层
  • BLL 业务逻辑层
  • DAL 数据访问层

每个顶层仅询问下层并且从来没有看到上面有任何东西。

当他们询问您您将如何构建 BLL 时,您可以这样写:

namespace Company.BLL
{
  // let's create an interface so it's easy to create other BLL's if needed
  public interface ICompanyBLL
  {
      public int Save(Order order, UserPermissions user);
  }

  public class Orders : ICompanyBLL
  {
    // Dependency Injection so you can use any kind of BLL 
    //   based in a workflow for example
    private Company.DAL db;
    public Orders(Company.DAL dalObject)
    {
      this.db = dalObject;
    }

    // As this is a Business Layer, here is where you check for user rights 
    //   to perform actions before you access the DAL
    public int Save(Order order, UserPermissions user)
    {
        if(user.HasPermissionSaveOrders)
            return db.Orders.Save(order);
        else
            return -1;
    }
  }
}

作为我正在创建的项目的实例:

在此处输入图像描述

PL 都是公开的服务,我的 DAL 处理对数据库的所有访问,我有一个服务层处理 2服务的版本,旧的 ASMX 和新的 WCF 服务,它们通过接口公开,因此我可以轻松地即时选择用户将使用的服务

public class MainController : Controller
{
    public IServiceRepository service;

    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        ...

        if (thisUser.currentConnection.ws_version == 6)
            // Use old ASMX Web Service
            service = new WebServiceRepository6(url, ws_usr, ws_pwd);

        else if (thisUser.currentConnection.ws_version == 7)
            // Use the brand new WCF Service
            service = new WebServiceRepository7(url, ws_usr, ws_pwd);

        ...

    }
}

在上面的代码中,我只是使用依赖注入来分离另一层的知识,因为在这一层(表示层,因为这是 MVC 项目中的控制器)它不应该关心如何调用服务以及用户使用的服务ServiceA 而不是 ServiceB...它需要知道的是,调用 IService.ListAllProjects() 将给出正确的结果。

您开始划分建议,如果服务连接中出现问题,您知道这与表示层无关,它是服务层(在我的例子中),并且很容易修复,并且可以轻松部署新的服务。 dll 而不是再次发布整个网站...

我还有一个助手,它保存我在所有项目中使用的所有业务对象

我希望它有帮助。

a 3 tier Architecture is composed by 3 Main Layers

  • PL Presentation Layer
  • BLL Business Logic Layer
  • DAL Data Access Layer

each top layer only asks the below layer and never sees anything on top of it.

When They ask you about How will you build your BLL, you can write something like:

namespace Company.BLL
{
  // let's create an interface so it's easy to create other BLL's if needed
  public interface ICompanyBLL
  {
      public int Save(Order order, UserPermissions user);
  }

  public class Orders : ICompanyBLL
  {
    // Dependency Injection so you can use any kind of BLL 
    //   based in a workflow for example
    private Company.DAL db;
    public Orders(Company.DAL dalObject)
    {
      this.db = dalObject;
    }

    // As this is a Business Layer, here is where you check for user rights 
    //   to perform actions before you access the DAL
    public int Save(Order order, UserPermissions user)
    {
        if(user.HasPermissionSaveOrders)
            return db.Orders.Save(order);
        else
            return -1;
    }
  }
}

As a live example of a project I'm creating:

enter image description here

PL's are all public exposed services, my DAL handles all access to the Database, I have a Service Layer that handles 2 versions of the service, an old ASMX and the new WCF service, they are exposes through an Interface so it's easy for me to choose on-the-fly what service the user will be using

public class MainController : Controller
{
    public IServiceRepository service;

    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        ...

        if (thisUser.currentConnection.ws_version == 6)
            // Use old ASMX Web Service
            service = new WebServiceRepository6(url, ws_usr, ws_pwd);

        else if (thisUser.currentConnection.ws_version == 7)
            // Use the brand new WCF Service
            service = new WebServiceRepository7(url, ws_usr, ws_pwd);

        ...

    }
}

In the code above, I simply use Dependency Injection to separate the knowladge of the other layer, as at this layer (the Presentation Layer as this is a Controller in a MVC project) it should never care about how to call the Service and that the user uses ServiceA instead of ServiceB... What it needs to know is that calling a IService.ListAllProjects() will give the correct results.

You start dividing proposes and if a problem appears in the service connection, you know that's nothing to do with the Presentation Layer, it's the service Layer (in my case) and it's easy fixed and can be easily deployed a new service.dll instead publishing the entire website again...

I also have a helper that holds all Business Objects that I use across all projects.

I hope it helps.

余罪 2024-12-13 01:48:11

业务逻辑定义为与应用程序数据的检索、处理、转换和管理有关的任何应用程序逻辑;业务规则和政策的应用;并确保数据的一致性和有效性。为了最大限度地提高重用机会,业务逻辑组件不应包含特定于用例或用户故事的任何行为或应用程序逻辑。业务逻辑可以进一步细分为以下两类:

  • 业务工作流。 UI 组件从用户收集所需数据并将其传递到业务层后,应用程序可以使用这些数据来执行业务流程。许多业务流程涉及多个步骤,这些步骤必须以正确的顺序执行,并且可以通过编排相互交互。业务工作流定义和协调长期运行、多步骤的业务流程,并且可以使用业务流程管理工具来实施。它们使用业务流程组件来实例化工作流组件并对其执行操作。
  • 业务实体 业务实体,或更一般地说,业务对象,封装了在应用程序中表示现实世界元素(例如客户或订单)所需的业务逻辑和数据。它们存储数据值并通过属性公开它们;包含和管理应用程序使用的业务数据;并提供对业务数据和相关功能的有状态编程访问。业务实体还验证实体内包含的数据并封装业务逻辑,以确保一致性并实现业务规则和行为。

Business logic is defined as any application logic that is concerned with the retrieval, processing, transformation, and management of application data; application of business rules and policies; and ensuring data consistency and validity. To maximize reuse opportunities, business logic components should not contain any behavior or application logic that is specific to a use case or user story. Business logic can be further subdivided into the following two categories:

  • Business Workflow. After the UI components collect the required data from the user and pass it to the business layer, the application can use this data to perform a business process. Many business processes involve multiple steps that must be performed in the correct order, and may interact with each other through an orchestration. Business workflow define and coordinate long running, multi step business processes, and can be implemented using business process management tools. They work with business process components that instantiate and perform operations on workflow components.
  • Business Entity Business Entity entities, or—more generally—business objects, encapsulate the business logic and data necessary to represent real world elements, such as Customers or Orders, within your application. They store data values and expose them through properties; contain and manage business data used by the application; and provide stateful programmatic access to the business data and related functionality. Business entities also validate the data contained within the entity and encapsulate business logic to ensure consistency and to implement business rules and behavior.
翻身的咸鱼 2024-12-13 01:48:11

业务层负责所有业务逻辑层。例如
你有组织,所以员工的组织和集合。
在员工对象中需要实施一些限制或一些规则。
该规则将在这一层实现。

Business layer layer that responsible for all business logic. For example
you have Organizarion so organization and collection of employee.
In employee object need to implement some restriction or some rules.
This rules will be implemented in this layer.

撩心不撩汉 2024-12-13 01:48:11

3 层如下,

  1. 您在一层中进行演示。
  2. 您的应用程序逻辑位于其他层——称为业务层。
  3. 您的数据访问类位于第三层。 ——称为数据层。

网络表单将成为表示层
因此,根据我的理解,对于员工类,在 ASP.Net 代码隐藏文件中执行的任何操作都可以被视为业务层,因为您使用 if/else 等应用业务规则。
App_Code 文件夹中的数据访问类将是数据层。

对于桌面应用程序,表单设计将是表示层,表单代码将是业务层,与访问数据库相关的任何内容将是数据层。

3 Tier is as follows,

  1. Your presentation in one layer.
  2. Your application logic in other layer -- called business layer.
  3. Your Data Access classes in third layer. -- called Data Layer.

Webforms will be presentation layer
So for employee class doing anything in ASP.Net code behind file can be considered business layer per my understanding as you are applying business rules using if/else and so forth.
Data Access classes in App_Code folder would be Data Layer.

In case of desktop apps form designs would be presentation layer, form code will be business layer and anything related to accessing database would be data layer.

年华零落成诗 2024-12-13 01:48:11

三层架构是一种由逻辑计算的三个“层”或“层”组成的软件架构。它们通常在应用程序中用作特定类型的客户端-服务器系统。三层架构通过模块化用户界面、业务逻辑和数据存储层,为生产和开发环境提供了许多好处。

业务逻辑层:业务逻辑是管理最终用户界面和数据库之间通信的编程。业务逻辑的主要组成部分是业务规则和工作流。

业务逻辑层 (BLL),充当表示层和 DAL 之间数据交换的中介。在实际应用程序中,BLL 应作为 App_Code 文件夹中的单独类库项目实现,以简化项目结构。下面说明了表示层、BLL 和 DAL 之间的架构关系。

BLL 将表示层与数据访问层分开并强加业务规则
BLL

A 3-tier architecture is a type of software architecture which is composed of three “tiers” or “layers” of logical computing. They are often used in applications as a specific type of client-server system. 3-tier architectures provide many benefits for production and development environments by modularizing the user interface, business logic, and data storage layers.

Business Logic Layer: Business logic is the programming that manages communication between an end user interface and a database. The main components of business logic are business rules and workflows.

A Business Logic Layer (BLL) that serves as an intermediary for data exchange between the presentation layer and the DAL. In a real-world application, the BLL should be implemented as a separate Class Library project in App_Code folder in order to simplify the project structure. below illustrates the architectural relationships among the presentation layer, BLL, and DAL.

The BLL Separates the Presentation Layer from the Data Access Layer and Imposes Business Rules
BLL

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文