72 votes

Business logic: Database vs code

See How much business logic should the database implement? for previous discussion. In general, everyone wants things done in the layer they control. Because then they control it. Every database ...
user avatar
  • 18.2k
35 votes
Accepted

Separating business logic from data tempts me to use instanceof

Your problem is that you're trying to use both rich domain models I always try to use polymorphism and anaemic domain models I try to separate data from business logic at the same time. Both are ...
user avatar
31 votes
Accepted

What does "business logic" actually mean if not "all non-3rd party code"?

I'll give you some tips regarding CRUD applications, since I don't have much experience in games or graphically intensive apps: Business logic usually involves rules the owner of the business has ...
user avatar
29 votes
Accepted

How exactly should a CQRS Command be validated and transformed to a domain object?

The following answer is in the context of the CQRS style promoted by the cqrs.nu in which commands arrive directly on the aggregates. In this architectural style the application services are being ...
user avatar
24 votes
Accepted

What exactly is a business rule?

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 ...
user avatar
22 votes
Accepted

where exactly should python business logic be placed in django

I have done a lot of searching but I am still not able to figure out where exactly should I place this Python file containing all the logic. There are a number of options, depending on what your ...
user avatar
  • 3,043
22 votes

Separating business logic from data tempts me to use instanceof

Though Philip Kendall's answer has a point, I think it is oversimplifying. One can separate data from behaviour and still use object oriented means and polymorphism. If you need your data (Bar, Baz) ...
user avatar
  • 186k
20 votes

Business logic: Database vs code

I am very firmly of the view that when ever possible, business logic should be kept in the software layer and not the database layer. Note, that when ever possible falls far short of always. There ...
user avatar
  • 9,855
19 votes
Accepted

Business logic vs Service layer

"Service layer" is an architectural term. It refers to a portion of the system that sits somewhere in the middle of a multi-tier architecture, below the user interaction layer but above the data ...
user avatar
  • 24.8k
18 votes
Accepted

What is the difference between business and application logic?

I agree with SO's LoztInSpace that this is quite opinionated answer and that everyone can have slightly different definitions. Especially if historical influences are involved. This is how I would ...
user avatar
  • 35.6k
15 votes
Accepted

Where should business logic sit in microservice architecture?

People often hear "micro-service" and think "nano-service", and this can cause some confusion. These are micro-services, so you don't need a separate service for every single entity. Everything you ...
user avatar
12 votes
Accepted

When should I use stored procedures?

You have a couple of perfectly good scenarios already. There are lots of other reasons too. EF is really good at CRUD and at pretty straight forward reporting. Sometimes, though, EF is not the ...
user avatar
  • 2,378
12 votes
Accepted

Using static type checking to protect against business errors

You are essentially asking for a unit system (no, not unit tests, "unit" as in "physical unit", like meters, volts etc.). In your code Age represents time and Pounds represents mass. This leads to ...
user avatar
  • 3,496
10 votes

Business logic: Database vs code

Two very important points are missing in your pro-database arguments: performance: database code is executed with direct access to the data, thus avoiding unnecessary transfers (be it across ...
user avatar
  • 68.6k
10 votes
Accepted

Entity Framework and avoiding the Anemic Domain Model

The issue is, you are using EF objects as domain objects in the first place. EF objects are data models NOT business models. You need to declare business objects which give you the freedom to do as ...
user avatar
10 votes

How exactly should a CQRS Command be validated and transformed to a domain object?

One fundamental premise of DDD is that domain models validate themselves. This is a critical concept because it elevates your domain as the responsible party for making sure your business rules are ...
user avatar
9 votes
Accepted

Should access logic go in controllers?

It is perfectly acceptable to put security/permissions logic in the controller method. The purpose of the controller method is to coordinate service calls to the service layer or business logic layer ...
user avatar
9 votes

Desktop to Web - How to deal with user-interactive workflows

Your primary difficulties I feel are that you have a mismatch between a very linear and custom workflow in an older application that do not coincide with the user interaction workflows that are common ...
user avatar
  • 26.3k
9 votes
Accepted

Entirely separate business logic layer from MVC

For me there is no question to be answered here, you should always strive to separate out your components as much as possible. At a bare minimum, for every new project I create I do the exact ...
user avatar
  • 598
9 votes
Accepted

Domain Objects and How they Access the Database

No, domain objects should not have any idea of the existence of a repository, or even a repository interface. If you feel the need to do this, that means there is an underlying issue with your design (...
user avatar
9 votes

Separation of application logic and domain logic in Clean Architecture

You don't need a one-to-one mapping of interactors and entities. I believe such a design would be harmful. DDD is all about context boundaries and the ubiquitous language within those boundaries. ...
user avatar
8 votes

where exactly should python business logic be placed in django

Daniel Greenfeld, co-author of "Two Scoops of Django, recommends the business logic should be in the models "when possible, or in the forms if you must." As for Bart's possible duplicate, django may ...
user avatar
  • 181
8 votes

How to clean up a business logic class that does too many things without injecting a ton of classes into it?

There is nothing wrong per se with a class BusinessLogic which orchestrates the logic of calling methods of a huge list of other objects, as long as one does not mix up different levels of abstraction....
user avatar
  • 186k
7 votes

How much logic can be put into a command? Or differently: What kind of logic is command pattern for?

Command Pattern is generally used to decouple WHAT from WHO, and WHAT from WHEN. This is the benefit of having a simple interface as simple as: public abstract class Command { public abstract ...
user avatar
  • 1,128
7 votes
Accepted

business rules, business proceses and business logic

A business process is a series of actions that are executed by a business to perform a particular task. For example, when a customer places an order with a company that company goes through a process ...
user avatar
  • 6,232
7 votes
Accepted

Design: Should Undo/Redo functionality be part of the business layer of an app?

Surely this totally depends on your business. Example 1: document editor with save functionality The editor itself might give you undo/redo as you edit, but those commands arent persisted via save. ...
user avatar
  • 65k
7 votes

Is it good practice to put service business logic based on audit trail?

It depends (but I guess for most real-world situations the answer is no, you risk to run into trouble). A general-purpose audit trail may collect data which, depending on the details, might be ...
user avatar
  • 186k
7 votes

What defines a business rule, as opposed to application or presentation logic?

A business rule is defined by business people and relates to business matters, regardless of the way these rules are implemented. Unambiguous examples: The change of the bank account of a ...
user avatar
  • 68.6k
6 votes

Project structure: where to put business logic

I think you got Fowler wrong, he is advocating 3, not 1 (see http://www.martinfowler.com/bliki/AnemicDomainModel.html). Note that he is not talking about "business logic inside entity classes", he is ...
user avatar
  • 186k
6 votes

Should access logic go in controllers?

It is helpful to distinguish two types of access control: Vertical - functions that some users can access and some users cannot. For example, anyone can view the home page, but only admin can ban a ...
user avatar
  • 1,663

Only top scored, non community-wiki answers of a minimum length are eligible