15

This question already has an answer here:

I'm trying to better organize my application architecture, so I've been doing some reading, but I keep running into references to "Business Logic" and "Business Rules". I've never really understood what these actually are. I generally just focus on Use Cases and "User Stories". Could someone explain what Business Logic and Business Rules are, and how they are related to Use Cases?

All the definitions I've found seem to pertain to actual businesses, not software development.

Because software is not always representative of a business, does that mean that software does not always have business logic? Or...

marked as duplicate by jmoreno, user40980, gnat, Bart van Ingen Schenau, GlenH7 Oct 30 '14 at 15:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

17

People use the terms "business rule" and "business logic" to refer to the portion of your application that is specific to your application and represents the core behavior of how things are supposed to work as opposed to generic functionality that could be useful in software written for a different client/business/customer base or code that exists to support the infrastructure of the application.

Often business logic is subject to change when the needs of the customer change, so we like to put it in a special place/tier so that we can modify it as needed.

Although the term seems to imply otherwise, non-business software also has business logic. For example, a rule that states that "when a user does xyz, the application should validate something" can be classified as a business rule.

Utility code, such as parsing/processing/data access and such would not be considered business logic.

It's kind of a nebulous term and could mean different things to different people in different contexts. It's not worth getting hung up on. The general idea is to separate your application into logical portions, each of which is responsible for something specific. How exactly this is done is something you learn from experience and working on well-designed large applications. But there aren't any hard and fast rules. Ask three good developers and you'll get six opinions.

  • 1
    Thanks, that's a really helpful explanation. I was struggling to understand a portion of a talk about architecture where the speaker stated that ".. this part handles your business rules" ( or something to that effect ). – moss Oct 30 '14 at 0:10
  • 3
    Nice explanation. Two clear examples might be useful. 1. Tax rules are a clear example of business rules. 2. A transaction count would be an implementation detail. I would also add that sometimes businesses have "business rules" that are artifacts of previous system implementations, whether computer or manual. They become part of the business process, and can easily be perpetuated without deep understanding for their purpose. – andy256 Oct 30 '14 at 2:02
  • @andy256 - both good points, thanks. Tax rules are a good example of business logic in business software, OP seemed to wonder how business logic might be used in consumer-software. But your example is helpful nonetheless. – Aaron Greenwald Oct 30 '14 at 2:18
  • Ask me and you'll get up to six opinions. Business rules are fickle at best, even when based on laws or procedures. The precise circumstances will depend on who's asking, what's being done, and what policies are in effect. Rules are not meant to be broken, and so business rules often dictate things that otherwise often don't make sense-- because some law requires it or some policy forbids it, whatever "it" may be. – phyrfox Oct 30 '14 at 5:34
4

Heres an excerpt from wikipedia

It is a rule that defines or constrains some aspect of business and always resolves to either true or false. Business rules are intended to assert business structure or to control or influence the behavior of the business Business rules describe the operations, definitions and constraints that apply to an organization. Business rules can apply to people, processes, corporate behavior and computing systems in an organization, and are put in place to help the organization achieve its goals.

With respect to what @aarong said, business rules or business logic doesn't really mean you require some form of business entity to make this up.

This can mean any constraint or definition of a process that your application is supposed to do. These rules are meant to assert the behavior of your application and what it does.

For example, lets put this logic in an atm machine.

Business Rules could be:

  • The user should have an atm card
  • The user should know the pin to the atm card
  • The amount the user is trying to withraw shouldn't exceed the account balance
  • In case of any errors, revert an changes made to the system and reverse transactions if possible

or in a more common place like facebook:

  • You need a facebook account to login
  • you must be logged in to add friends
  • the user must be able to select who can see their posts and pictures
  • the user should be notified about friend requests
  • the user can accept or decline friend requests

stuff like that.

0

Business rules are rules that exist in the problem domain that define or restrict processes in that domain.

These are rules that may be applied by software.

The use cases are documented observations of the business rules in practice.

Example, if the problem domain is prescribing, then:

  1. a business rule could be "Can't do refills on Control-II Medications".
  2. a use case or story could be "Patient requests refill on Medication... System denies refill because refills aren't allowed on Control-II Medication..."

Business rules aren't necessarily associated with computer applications.

When you see the term in a book, you can generally think of it as "Requirements" although requirements encompass more than just business rules.

-2

You could call the business logic where you decide what you will do with the data that you got from the user. There you can manipulate it and return or save on database. What you do with that data depends on the client needs.

  • 2
    Do you have any supporting references for your statement? – Adam Zuckerman Oct 29 '14 at 23:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.