ArticleslgStudy

computer science

Business logic

Business logic is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Business logic rather than just read about it. In short: In computer software, business logic or domain logic is the part of the program that encodes the real-world business rules that determine how data can be created, stored, and changed. It is contrasted with the remainder of the software that might be concerned with lower-level details of managing a database or displaying the user interface, system infrastructure, or generally connecting various parts of the program.

Business logic — main illustration
Business logic — illustration

Key takeaways

  • Business logic belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Business logic to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Business logic from memory before moving on to harder problems.

Reference excerpt

In computer software, business logic or domain logic is the part of the program that encodes the real-world business rules that determine how data can be created, stored, and changed. It is contrasted with the remainder of the software that might be concerned with lower-level details of managing a database or displaying the user interface, system infrastructure, or generally connecting various parts of the program.

Details and example and more Business logic:

Prescribes how business objects interact with one another Enforces the routes and the methods by which business objects are accessed and updated Business rules:

Model real-life business objects (such as accounts, loans, itineraries, and inventories) Business logic comprises:

Workflows that are the ordered tasks of passing documents or data from one participant (a person or a software system) to another. Business logic should be distinguished from business rules. Business logic is the portion of an enterprise system which determines how data is transformed or calculated, and how it is routed to people or software (workflow). Business rules are formal expressions of business policy. Anything that is a process or procedure is business logic, and anything that is neither a process nor a procedure is a business rule. Welcoming a new visitor is a process (workflow) consisting of steps to be taken, whereas saying every new visitor must be welcomed is a business rule. Further, business logic is procedural whereas business rules are declarative. For example, an e-commerce website might allow visitors to add items to a shopping cart, specify a shipping address, and supply payment information. The business logic of the website might include a workflow such as:

The sequence of events that happens during checkout, for example a multi-page form which first asks for the shipping address, then for the billing address, next page will contain the payment method, and last page will show congratulations. There will also be business rules of the website:

Adding an item more than once from the item description page increments the quantity for that item. Specific formats that the visitor's address, email address, and credit card information must follow. A specific communication protocol for talking to the credit card network The web site software also contains other code which is not considered part of business logic nor business rules:

Peripheral content not related to the core business data, such as the HTML that defines the colors, appearance, background image, and navigational structure of the site Generic error-handling code (e.g., which displays the HTTP Error Code 500 page) Initialization code that runs when the web server starts up the site, which sets up the system Monitoring infrastructure to make sure all the parts of the site are working properly (e.g., the billing system is available) Generic code for making network connections, transmitting objects to the database, parsing user input via HTTP POST events, etc.

Business logic and tiers/layers

Business logic could be anywhere in a program. For example, given a certain format for an address, a database table could be created which has columns that correspond exactly to the fields specified in the business logic, and type checks added to make sure that no invalid data is added. Business logic often changes. For example, the set of allowable address formats might change when an online retailer starts shipping products to a new country. Thus it is often seen as desirable to make the code that implements the business logic relatively isolated, or loosely coupled. This makes it more likely that changes to business logic will require a small set of code changes, in only one part of the code. Distant but strongly coupled code also creates more of a risk that the programmer will only make some of the necessary changes and miss part of the system, leading to incorrect operation. A multitier architecture formalizes this decoupling by creating a business logic layer which is separate from other tiers or layers, such as the data access layer or service layer. Each layer "knows" only a minimal amount about the code in the other layers—just enough to accomplish necessary tasks. For example, in a model–view–controller paradigm, the controller and view layers might be made as small as possible, with all the business logic concentrated in the model. In the e-commerce example, the controller determines the sequence of web pages in the checkout sequence, and is also responsible for validating that email, address, and payment information satisfy the business rules (rather than leaving any of that up to the database itself or lower-level database access code). Alternative paradigms are possible. For example, with relatively simple business entities, a generic view and controller could access database objects which themselves contain all the relevant business logic about what formats they accept and what changes are possible (known as the database model). Some tiered schemes use either a distinct application layer or a service layer, or consider the business logic layer to be the same as one of those.

Tools and techniques Business logic can be extracted from procedural code using a business rule management system (BRMS). The business rules approach of software development uses BRMSs and enforces a very strong separation of business logic from other code. User interface management systems are another technology used to enforce a strong separation between business logic and other code. The magic pushbutton is considered an "anti-pattern": a technique that in this case creates undesirable constraints which make it difficult to code business logic in an easy-to-maintain way. A domain model is an abstract representation of the data storage types required by business rules.

See also Drakon-chart Relocating logic Business process modeling Model–view–controller

References

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Business logic

Start with the simplest possible case. Write down what Business logic claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Business logic before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Business logic ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Business logic

In research
Business logic appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Business logic in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Business logic is common in secondary-school and first-year university syllabi. It links to neighbouring topics Business processes, Software architecture, so understanding it makes those chapters shorter.
In everyday life
Look for Business logic outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Business logic” →

How to study Business logic in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Business logic means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Business logic out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Business logic in simple terms?

In computer software, business logic or domain logic is the part of the program that encodes the real-world business rules that determine how data can be created, stored, and changed. It is contrasted with the remainder of the software that might be concerned with lower-level details of managing a…

Why does Business logic matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Business logic?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Business logic.

Tags

  • Business processes
  • Software architecture

Keep exploring