本文介绍了在BLL层VS BLL方法单一重载方法具有DAL方法一到一一对应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果

假设我们创建3层模块,这使我们能够显示/创建/编辑文章。文章是:

Assume we create 3-tier module, which enables us to display/create/edit articles. Articles are:

•组织成类结果
•以前的文章可以发布,管理员可以通过设置的批准的领域的文章数据库表的到的真正的结果予以批准
•通过设置的 MembersOnly 的字段(文章表的),管理员还可以指定是否特定物品可以由任何人或只有注册用户才能查看结果
文章的表还具有的 ExpiredDate 的领域,这在什么时候会在文章到期,因此不再发布

• organized into categories
• before article can be published, admin has to approve it by setting Approve field of Articles DB table to true
• by setting MembersOnly field ( Articles table ) admin can also specify whether particular article can be viewed by anybody or only by registered users
Articles table also has ExpiredDate field, which tells when will the article expire and thus no longer be published

结果

一)的 DAL 的层,我们提供的方法的 GetAllArticles,GetArticlesByCategory,GetPublishedArticles和GetPublishedArticlesByCategory 的从数据库中检索文章

a) At DAL layer we provide methods GetAllArticles, GetArticlesByCategory, GetPublishedArticles and GetPublishedArticlesByCategory for retrieving articles from the DB

BLL 的层,我们使用的 GetArticles()的重载调用所有上述DAL方法。

At BLL layer we use GetArticles() overloads to call all of the above DAL methods.

结果


  • 什么是一些采用单重载的方法时所带来的好处的 BLL 的层代替的 BLL 的方法有一对一一对应的 DAL 的方法呢?唯一的好处我能想到的是,这种方式同样的 ObjectDataSource控件的控制可以调用的 GetArticles两个或两个以上()的过载,根据参数的值,例如:

  • What are the some of the benefits of using single overloaded method at BLL layer instead of BLL methods having one-to-one correspondence with DAL methods? Only advantage I can think of is that this way same ObjectDataSource control can call two or more of GetArticles() overloads, depending on the value of parameters, for example:

 public static List<Article> GetArticles(bool publishedOnly)
 {
    if (!publishedOnly)
         return GetArticles();
      ...
 }


结果


  • 如果你不还设计的 UI 的层,因此不能确定哪些方法 UI程序员的将preFER最,这将是最好的做法为的 DLL 的层提供的四GetArticles + GetAllArticles,GetArticlesByCategory,GetPublishedArticles和GetPublishedArticlesByCategory重载

  • If you don’t also design UI layer and thus can’t be sure which methods UI programmer will prefer the most, would it be best practice for DLL layer to provide four overloads of GetArticles + GetAllArticles, GetArticlesByCategory, GetPublishedArticles and GetPublishedArticlesByCategory?

结果

2)当设计的 DAL方法的检索数据库的数据,你怎么可以预先知道/ predict(不首先设计UI),到底哪些方法(用于访问DB)我们应在DAL层创建?

2) When designing DAL methods to retrieve data from DB, how can you in advance know/predict ( without first designing the UI ), exactly which methods (for accessing DB) we should create at the DAL layer?

也就是说,在previous例如我有几种方法的基础上的参数(基于的类别的他们属于,我们是否只想要的公布号码检索文章的文章等)。假设我卖这个模块向第三方UI开发人员,那么有没有办法知道哪些数据访问方法,他们将preFER之最:

Namely, in the previous example I’ve had several methods for retrieving articles based on number of parameters ( based on category they belong to, whether we only want published articles etc). Assuming I’m selling this module to third party UI developers, then there is no way to know which data access methods they would prefer the most:

结果

一个),所以我应该创建多达我能想到的(一个用于获得那些已经过期获取那些已经过期的所有文章的所有文章,一个,但从未发表,一个是让所有物品的数据访问方法未发布,一个让所有的文章,可以查看由注册用户只有...)?

a) so should I create as many data access methods as I can think of ( one for getting all articles that are already expired, one for getting all articles that are already expired, but were never published, one for getting all articles that are not published, one for getting all articles that can be view by registered users only… ) ?

结果

二)即使所有三层都是我自己写的 - 我应该还是创建多达我能想到的数据访问方法?

b) Even if all three layer are written by myself – should I still create as many data access methods as I can think of?

结果

感谢名单

结果

编辑:

要实现这个的一种常见方法是使用接口来定义该API的行为。

A)我不知道我理解这一点。其中的类应该实现这个接口?也许DLL类?换句话说,如果我的DLL类的名称是文章,那么第三方将获得命名ChildArticle从第三类,其中ChildArticle也将实现这个接口?还是你的意思是什么东西?

a) I’m not sure I understand this. Which class should implement this interface? Perhaps DLL class? In other words, if the name of my DLL class is Article, then third party would derive class named ChildArticle from Article, where ChildArticle would also implement this interface? Or did you mean something else?

结果

二)反正,据我了解,提供接口(声明定义了额外的DLL的方法来检索数据库的文章),还需要DAL类已经适当的方法来定义,这将通过在声明的方法被调用接口?

b) Anyways, as far as I understand it, providing interface ( which declares defines additional DLL methods to retrieve articles from DB ) would also require DAL class to already have appropriate methods defined, which would be called by methods declared in the interface?

结果

要贵点,我相信这是一个好主意,preFER在BLL较少的粗粒度的方法来覆盖所有的整个业务操作所需的功能。

我不熟悉这个词,但你的概率暗示我们应该preFER超载GetArticles()在GetAllArticles,GetArticlesByCategory,GetPublishedArticles和GetPublishedArticlesByCategory?

I’m not familiar with this term, but you’re prob suggesting that we should prefer overloaded GetArticles() over GetAllArticles, GetArticlesByCategory, GetPublishedArticles and GetPublishedArticlesByCategory?

结果

一个)的API的设计是严格相关到什么是指以实现和由谁将被使用。
  在实践中,这意味着你应该知道你的API的目标受众,并给予他们只需要怎样把工作做好。

除非我亲自面试,将购买我的产品的人,我可以猜出大致哪些方法,他们会发现有用的,但该空间内,仍然有任何数量的可能的方法,我可以定义。因此,我怎么会知道他们是否也将发现,比如说,GetArticles使用()超载来检索已经过期?!

Unless I personally interview the people that would buy my product, I can generally guess which methods they would find useful, but within that space, there are still any number of possible methods I could define. Thus, how should I know whether they would also find use for, say, GetArticles() overload which retrieves articles that already expired?!

结果

在对方这是完全没有有在DAL许多较小的以数据为中心的方法与特定的数据来工作。

如果不是DLL,应该DAL有尽可能多的数据访问方法,我可以拿出(当然对于特定的目标受众)?

If not DLL, should DAL have as many data access methods as I can come up with ( for particular target audience of course )?

结果

第二编辑:

一个少数可扩展性点可以内置到API,以获得某种程度的灵活性。实现这个的一种常见方法是使用接口来定义该API的行为。这将允许消费者通过提供自定义实现更换或扩展的内置功能的片

假设我创建了一个BLL层,然后提供一些额外的接口,消费者可以实现延长BLL的内置的功能。但对于消费者能够实现这些接口,他们将需要访问BLL的源$ C ​​$ C,对不对?但是,如果我不想要什么消费者查看BLL的源$ C ​​$ C?

Assume I create a BLL layer and then provide some additional interfaces, which consumers could implement to extend BLL’s build-in functionality. But for consumers to be able to implement these interfaces, they will need to have access to BLL’s source code, right? But what if I don’t want consumers to view BLL’s source code?

结果

接口应层之间存在。更具体地,类应该只通过接口与来自其它层类交互

一)因此,即使DAL的内置功能应该通过接口被暴露?但为什么?也就是说,如果我们可以使用抽象类而不是接口,那么这个类可能已经实现了共同的,从这个抽象类继承所有供应商类的一些实用功能?另一方面,如果DAL使用接口代替,然后共同所有提供商实用功能将必须为每个提供一旦实施,这可能意味着大量的冗余编码!

a) So even DAL’s built-in functionality should be exposed through interfaces? But why? Namely, if we’d use abstract class instead of interfaces, then this class could already implement some utility functions common to all provider classes that inherit from this abstract class?! On the other hand, if DAL uses interfaces instead, then utility functions common to all providers will have to be implemented once for each provider, which could mean a lot of redundant coding?!

结果

二)不管怎么说,我不太看到利益(除非我们提供,消费者可在延伸具有不同层通过接口进行交互类的基本功能)接口?

b) Anyways, I don’t quite see the benefits ( except when we provide interfaces with which consumers could extend the basic functionality ) in having classes from different layers interacting through interfaces?

结果

有关增加透明度,我认为最好是有接受单个参数的方法。该参数将是包含的所有数据一起工作的方法的对象。一些数据可能是需要的,一些可能是可选的,并且会影响操作的效果。

如果我知道UI将广泛使用对象的数据源控件,我应该还是preFER BLL定义一个方法(其与该方法中的所有数据对象作为参数,这种方法一起工作),而不是方法重载?

If I know UI will extensively make use Object Data Source controls, should I still prefer BLL to define a single method (this method having as parameter an object with all the data for the method to work with) instead of method overloads?

欢呼队友

推荐答案

我冒昧地概括你的帖子在两个主要问题。我希望我设法捕捉你所要求的本质。

I took the liberty to summarize your post in two main questions. I hope I managed to capture the essence of what you are asking.

Q) 什么是由BLL暴露在DAL暴露intefaces和那些之间的关系?

A)的BLL是外向的API,因此它应该实现的功能就是有用的外部消费者的应用和公开它在某种程度上是有道理以他们。

DAL层,相反,是一个向内的API,它公开功能的在隐藏所使用的存储机制的细节的方法来检索和持久数据即可。

A) The BLL is an outward-facing API, and as such it should implement functionality that is useful to the external consumers of the application and expose it in a way that makes sense to them.
The DAL, on the contrary, is a inward-facing API that exposes functionality to retrieve and persist data in way that hides the details of the storage mechanism being used.

在总之,DAL着重于数据如何被重新presented和在应用程序内部管理,而BLL对焦在方式揭露的数据是有意义的消费者。

In short, the DAL focuses on how data is being represented and managed internally in the application, while the BLL focuses on exposing data in way that is meaningful to consumers.

Q) 公共API应该有多少方法都和哪些?

A)的API的设计是严格地与这是什么意思来实现,由谁来将使用它。
在实践中,这意味着你应该的知道你的API的目标受众,并给予他们只需要怎样把工作做好

既然是不可能predict所有可能的方式的API将被使用,它决定主使用情况,以支持它,并努力使他们的API中真正直接的方式是很重要的。一个好的原则要记住是艾伦凯曾经说过:

A) The design of an API is strictly related to what it is meant to achieve and by whom it will be used.
In practice, this means that you should know the target audience of your API, and give them only what they need to get the job done.
Since it is impossible to predict all the possible ways an API will be used, it is important to decide which main use cases to support, and work to make them really straightforward in the API. A good principle to keep in mind is what Alan Kay once said:

简单的事情,应该是简单的,
  复杂的事情应该是可能的。

扩展点可内置于API获得一定程度的灵活性。实现这个的一种常见方法是使用接口来定义该API的行为。这将允许消费者通过提供自定义实现更换或扩展的内置功能的碎片。

A few extensibility points can be built into the API to obtain a certain degree of flexibility. A common way to achieve this is to use interfaces to define the behavior of the API. This will allow consumers to replace or extend the pieces of the built-in functionality by providing custom implementations.

要贵点,我相信这是一个好主意,preFER在BLL 较少的粗粒度的方法来覆盖所有的整个业务运作所需的功能。
在另一边是完全正常的有许多较小的数据中心在DAL 的方法特定的数据来工作。

To your point, I believe it is a good idea to prefer fewer coarse-grained methods in the BLL to cover all the functionality required by an entire business operation.
On the other side it is perfectly fine to have many smaller data-centric methods in the DAL to work with specific pieces of data.

更新:



关于接口

接口应层之间存在。更具体地,类应该只通过接口与来自其它层类交互。
例如,DAL应该公开的接口用于访问数据类,如 IOrderHeaderTable IOrderRepository 的根据设计图案被使用。

该BLL应公开用于执行业务操作类,如 IOrderManagementWorkflow ICustomerService 的。

注意:层中常见的功能仍然可以放置在基类,因为像C#,VB.NET和Java现代的面向对象语言的类都可以从基类继承和实现一个或更多的接口。

另外,谁愿意外部各方通过实施任何提供的公共接口,可以这样做,而无需访问源$ C ​​$ C定制的内置功能。然而,接口应该是自我描述和详细记录,以便更容易为扩展理解它的语义。

UPDATE:

About interfaces
Interfaces should exist between layers. More specifically, classes should interact with classes from other layers exclusively through interfaces.
For example, the DAL should expose interfaces for the classes used to access data, like IOrderHeaderTable or IOrderRepository depending on the design pattern being used.
The BLL should expose classes used to execute business operations, like IOrderManagementWorkflow, or ICustomerService.
Note: common functionality inside a layer can still be placed in base classes, since in modern Object-Oriented languages like C#, VB.NET and Java a class can both inherit from a base class and implement one or more interfaces.
Also, external parties who wish to customize the built-in functionality by implementing any of the provided public interfaces can do so without needing access to the source code. Interfaces should however be self-describing and well-documented, in order to make it easy for extenders to understand its semantics.

关于BLL

该BLL应该明确它支持的业务逻辑。因此,它通常是有直接相关业务操作的方法是一个好主意。
而不是重载方法具有不同的参数,以工作为增加透明度,我认为最好是有一个接受单个参数的一种方法。该参数将是包含的所有数据一起工作的方法的对象。一些数据可能是需要的,一些可能是可选的,并且会影响操作的效果。

实现细节:这种BLL API是完全内置到ASP.NET Web窗体ObjectDataSource控件支持

About the BLL
The BLL should be explicit about the business logic it supports. Therefore it is generally a good idea to have methods that are directly related to business operations.
For added clarity, instead of overloading methods to work with different parameters, I believe it is better to have one method that accepts a single parameter. This parameter would be an object containing all the data for the method to work with. Some of that data could be required, some could be optional and would influence the effect of the operation.
Implementation detail: this kind of BLL API is fully supported by ObjectDataSource control built into ASP.NET Web Forms.

关于API

一个API应该包含所有方法的设计者可以通过用例的API的目的是确定的范围内拿出,以支持

这篇关于在BLL层VS BLL方法单一重载方法具有DAL方法一到一一对应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 01:07