三层架构中的业务层 [英] Business Layer in 3 tier Architecture

查看:239
本文介绍了三层架构中的业务层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我去接受采访,被要求展示我的业务层架构。我对三层体系结构有一些想法,但对于面试官面前要写些什么却真的不知道。
因此,假设我的项目与一个组织的员工打交道,那么我在那儿写了什么。它应该是我应该制作的任何类型的图还是某些编码部分。我在C#Framework 3.5中工作。我真的不明白在这个问题上还有什么要提的,所以请告诉我是否需要。

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.

编辑
我在winforms中工作。
我知道什么是业务层,但是由于业务层具有代码,所以我不确定要告诉采访者什么,显然我的项目有点大,所以代码很多。所以我应该在那写什么?

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??

推荐答案

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

a 3 tier Architecture is composed by 3 Main Layers


  • PL 表示层

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

  • 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.

当他们问您有关您将如何构建BLL 时,您可以编写以下内容:

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;
    }
  }
}

我正在创建的项目:

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

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);

        ...

    }
}

在上面的代码中,我只是使用依赖注入来分隔另一层的知识,因为在这一层(Presentation层,因为它是MVC项目中的Controller),所以它永远都不必在乎如何调用服务,并且用户使用 ServiceA 而不是 ServiceB ...。它需要知道的是调用 IService.ListAllProjects()会给出正确的结果。

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.

您开始分割建议,并且服务连接中是否出现问题,您知道这与表示层无关,它是服务层(在我的情况下),很容易修复,可以轻松地部署新的 service.dll 而不是发布整个网站...

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...

我还有一个助手,可以保存我在所有项目中使用的所有 Business Objects

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

我希望对您有所帮助。

这篇关于三层架构中的业务层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆