简体   繁体   English

业务层3

[英]business layer 3

为什么3层模型中的第二层称为“业务”层?

Because the business logic resides there. 因为业务逻辑驻留在那里。 That is - the logic that is specific to the business scenarios. 也就是说-特定于业务场景的逻辑。

Other layers should not have such logic. 其他层不应具有这样的逻辑。 Front end should display and gather data, database should store data, dao should retrieve and save data. 前端应显示和收集数据,数据库应存储数据,dao应检索和保存数据。

The business layer should perform the logic based on what is coming as input from the UI, and from the DB. 业务层应基于来自UI和数据库的输入执行逻辑。

It's 'business', because every software backs some business. 这是“业务”,因为每个软件都支持某些业务。

因为它特定于应用程序的性质(慈善机构,在线零售商和房地产经纪人可能都使用相同的Web服务器和数据库),但是中间的情况却大不相同。

In an OO application I like to think of the business layer as business rules, processes or workflows that are applied to the objects. 在OO应用程序中,我喜欢将业务层视为应用于对象的业务规则,流程或工作流。 However in many cases I have seen this to mean that the objects become nothing but POCO's (Plain Old C# Objects in C#, POJO's in Java etc). 但是,在许多情况下,我已经看到这意味着对象仅是POCO(在C#中为普通的旧C#对象,在Java中为POJO)等。 The problem with this is that the object's behaviour becomes detached from the object and moved into arbitrary "Business Logic" classes. 问题是对象的行为与对象分离,并移入任意的“业务逻辑”类。

My personal belief is that the "Business Layer" should act upon objects but not replace object an object's behaviour. 我个人认为,“业务层”应该作用于对象,但不能代替对象的行为。 This also allows for better implementation of other practices such as Open Closed Principle using inheritance and polymorphism. 这也可以更好地实现其他实践,例如使用继承和多态性的开放式封闭原则。

Consider this example "OCP" where the Area class would be the "Business Layer" but the various Shape objects contain the behaviour logic for each type of shape. 考虑以下示例“ OCP” ,其中Area类将是“业务层”,但是各种Shape对象包含每种形状类型的行为逻辑。 This way the Area code rarely, if at all needs to change. 这样,即使根本需要更改,区号也很少。

OK, here my 2 cents. 好吧,这是我的2美分。

Why? 为什么? Because that is how it is defined in the N-Tier paradigm . 因为这就是在N层范式中 定义的方式。 We cannot ask why something is named as such when it is defined as such. 我们不能问为什么在定义某事物时为何如此命名。

N-Tier paradigm is an old one - more than 10 years old. N-Tier范例是一个古老的范例-已有10多年的历史了。 N-Tiere design while at some point helped separating view logic from business logic, now is not trendy anymore. N-Tiere设计在某种程度上有助于将视图逻辑与业务逻辑分离,但现在已不再流行。

Today, Domain Driven Design aka DDD is the new paradigm where looks at the domain logic and builds the system on that. 如今, 域驱动设计 (又称DDD)是一种新的范例,它研究域逻辑并以此为基础构建系统。 Domain logic is everywhere, in database, in the UI as well as in the middle layer . 域逻辑无处不在,无论是在数据库中,在UI中还是在中间层中 So really your tables will be called Order , Topping , etc if you are making software for pizza shops whil it will have Account , Transaction if you are developing software for a bank. 因此,如果您正在为比萨店制作软件,那么实际上您的表将被称为OrderTopping等,而如果您正在为银行开发软件,则该表将具有AccountTransaction So business logic is everywhere, in the middle tier as well as in the UI or database. 因此,业务逻辑无处不在, 无论是在中间层还是在UI或数据库中。

So now while layered architecture is still accepted as a good architectural approach (which has a middle layer which is not called "business layer" anymore), N-Tier is not. 因此,现在尽管分层体系结构仍被认为是一种好的体系结构方法(其中间层不再称为“业务层”),但N-Tier却不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM