What exactly consists of 'Business Logic' in an application?

后端 未结 8 1370
走了就别回头了
走了就别回头了 2020-12-24 03:30

I have heard umpteen times that we \'should not mix business logic with other code\' or statements like that. I think every single code I write (processing steps I mean) con

8条回答
  •  时光说笑
    2020-12-24 04:07

    I think you confusing business logic with your application requirements. It's not the same thing. When someone explains the logic of his/her business it is something like:

    "When a user buys an item he has to provide delivery information. The information is validated with x y z rules. After that he will receive an invoice and earn points, that gives x% in discounts for the y offers" (sorry for the bad example)

    When you implement this business rules you'll have to think in secondary requirements, like how the information is presented, how it will be stored in a persistent way, the communication with application servers, how the user will receive the invoice and so on. All this requirements are not part of business logic and should be decoupled from it. This way, when the business rules change you will adapt your code with less effort. Thats a fact.

    Sometimes the presentation replicates some of the business logic, mostly in validating user input. But it has to be also present in the business logic layer. In other situations, is necessary to move some business logic to the Database, for performance issues. This is discussed by Martin Fowler here.

提交回复
热议问题