I've never encountered a well written business layer. Any advice?

后端 未结 9 1710
Happy的楠姐
Happy的楠姐 2021-02-02 00:54

I look around and see some great snippets of code for defining rules, validation, business objects (entities) and the like, but I have to admit to having never seen a great and

相关标签:
9条回答
  • 2021-02-02 01:21

    One problem I find is that even when you have a nicely designed business layer it is hard to stop business logic leaking out, and development tools tend to encourage this. For example as soon as you add a validator control to an ASP.NET WebForm you have let business logic leak out into the view. The validation should occur in the business layer and only the results of it displayed in the view. And as soon as you add constraints to a database you then have business logic in your database as well. DBA types tend to disagree strongly with this last point though.

    0 讨论(0)
  • 2021-02-02 01:23

    Possibly because in reality we are never able to fully decouple the business logic from the "process", the inputs, outputs, interface and that ultimately people find it hard to deal with the abstract let alone relating it back to reality.

    0 讨论(0)
  • 2021-02-02 01:24

    I’ve never encountered a well written business layer.

    Here is Alex Papadimoulis's take on this:

    [...] If you think about it, virtually every line of code in a software application is business logic:

    • The Customers database table, with its CustomerNumber (CHAR-13), ApprovedDate (DATETIME), and SalesRepName (VARCHAR-35) columns: business logic. If it wasn’t, it’d just be Table032 with Column01, Column02, and Column03.
    • The subroutine that extends a ten-percent discount to first time customers: definitely business logic. And hopefully, not soft-coded.
    • And the code that highlights past-due invoices in red: that’s business logic, too. Internet Explorer certainly doesn’t look for the strings “unpaid” and “30+ days” and go, hey, that sure would look good with a #990000 background!

    So how then is possible to encapsulate all of this business logic in a single layer of code? With terrible architecture and bad code of course!

    [...] By implying that a system’s architecture should include a layer dedicated to business logic, many developers employ all sorts of horribly clever techniques to achieve that goal. And it always ends up in a disaster.

    0 讨论(0)
  • 2021-02-02 01:28

    Martin Fowler has blogged extensively about DSLs. I would recommend starting there.

    http://martinfowler.com/bliki/dsl.html

    0 讨论(0)
  • 2021-02-02 01:29

    I imagine this is because business logic, as a general rule, is arbitrary and nasty. Garbage in, garbage out.

    Also, most of the really good business layers are most probably proprietary. ;-)

    0 讨论(0)
  • 2021-02-02 01:31

    Neither have I. We don't create a business layer in our applications. Instead we use MVC-ARS. The business logic is embedded in the (S) state machine and the (A) action.

    0 讨论(0)
提交回复
热议问题