37
            
            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 ...
                
            
       
        
            
                23
            
            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) ...
                
            
       
        
            
                17
            
            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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                10
            
            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.  ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 (...
                
            
       
        
            
                8
            
            votes
        
            
                
                Accepted
            
        
            
        How to keep track of growing catalog of business rules?
                    Requirements need to be documented. You are already attempting to do that, but requirements are often broken down into a number of categories:
Business requirements — Things like "A blog post ...
                
            
       
        
            
                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....
                
            
       
        
            
                8
            
            votes
        
            
                
                Accepted
            
        
            
            
        Should business logic classes be POJO only?
                    I read about three-tier architecture and I have a question: I read that in business logic (that is, what is in logic tier) there should be bare Java classes,
These bare Java classes are called POJO's ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                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 ...
                
            
       
        
            
                6
            
            votes
        
        
            
        Using static type checking to protect against business errors
                    In contrast to null's answer, defining a type for a "unit" can be beneficial if an integer isn't enough to describe the measurement. For instance, weight is often measured in multiple units within the ...
                
            
       
        
            
                6
            
            votes
        
            
                
                Accepted
            
        
        DDD - delegate business rule of domain object to external service
                    A Domain Object is not responsible for providing information outside of it's own context. Whether or not an API token is active is not something the token itself can answer, but is instead a question ...
                
            
       
        
            
                6
            
            votes
        
            
                
                Accepted
            
        
            
        Is My Data Access Layer Really My Domain?
                    Usually the naming of the layers depend on the architectural approach: 
The traditional layering is presentation / business logic / data access layer. 
Another popular variant is Fowler’s presentation ...
                
            
       
        
            
                5
            
            votes
        
            
                
                Accepted
            
        
            
        Does Presentation Logic constrain design of Business layer?
                    It's a good question. Sometimes the complexities of the real world make it harder to see the big picture, and/or are in conflict with our mental models. I'll have to digress a bit before I get to your ...
                
            
       
        
            
                5
            
            votes
        
            
                
                Accepted
            
        
            
            
        How to generalize this method for its duplicate/common logic?
                    The approach you're looking for is a code refactoring called "extract method" (or "extract function").  See here and/or here.
You take the common code and extract it into its own private ...
                
            
       
        
            
                5
            
            votes
        
        
            
            
        Presentation Layer Accessing Business Logic
                    System Requirement: The UI should only enable the Delete button for an Order when there are no products on the Order and the Order's status is 'Open'.
This is the classic requirement mistake of ...
                
            
       
        
            
                5
            
            votes
        
            
                
                Accepted
            
        
            
        Where should I place more complex business logic related to what a Web API does but consumed by a single client?
                    I think this boils down to the following situation:
there are two applications A and B
both need a common functionality / complex business logic for which duplication is not desirable
one wants to ...
                
            
       
        
            
                5
            
            votes
        
        
        How would you implement a promotion/discount system?
                    It's never possible to enumerate all possible use cases upfront. But some systems are more expandable than others.
Having maintained one of these that worked well for a point-of-sale system, I think ...
                
            
       
        
            
                5
            
            votes
        
        
            
        Preventing duplicate customers from company entry vs mobile sign-in
                    There is no proper way to do this automatically. How would you identify the same natural person? And if you could, how would you get the user's consent to merge the account? Maybe they want two ...
                
            
       
        
            
                5
            
            votes
        
            
                
                Accepted
            
        
        OO design - Process that relies on the current state of objects
                    There is a simple principle which helps you to avoid your program  drifting into a Big-Ball-Of-Mud architecture: make a clear separation between getting the data and processing it.
I would omit the ...
                
            
       
        
            
                4
            
            votes
        
            
                
                Accepted
            
        
            
        Should Extensions methods be used for Business logic
                    You cited 
  Extension methods enable you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.
and that is when you should use ...
                
            
       
        
            
                4
            
            votes
        
            
                
                Accepted
            
        
            
            
        Should data model logic live in database schema?
                    Yes!
Why? Because unique constraints are in everyone's best interest.
Now sure some could argue that the application can do that and might even have use cases where the unique constraint needs to be ...
                
            
       
        
            
                4
            
            votes
        
        
            
        Possible alternatives to excel as business logic implementation
                    You wrote 
  The project I'm working on is web based price calculation
and
  I'll only be here for 3 months and there are nobody in the office that can do any coding
Note that these two statements are ...
                
            
       
        
            
                4
            
            votes
        
        
        Presentation Layer Accessing Business Logic
                    What if there are new or changed business rules to determine when an Order can be deleted? While you could add a function .CanDelete() to the OrderDTO, it's the wrong place based on everything I've ...
                
            
       
        
            
                4
            
            votes
        
            
                
                Accepted
            
        
        Upholding business logic and invariants in an event sourced CQRS architecture
                    Many people have been getting confused over what CQRS is. They look at CQRS as being an architecture; it is not. CQRS is a very simple pattern that enables many opportunities for architecture that may ...
                
            
       
        
            
                4
            
            votes
        
        
            
            
        Where should "query" business logic be placed in Domain-driven design?
                    Decision which product to load/display belongs to business(domain) logic.
As part of the domain, you can introduce a "filter" object which can be passed to the data access layer which will ...
                
            
       
        
            
                4
            
            votes
        
        
        Patterns for returning messages/results from business logic to UI
                    OneOf is a pretty popular library among the .NET packages. Another really famous one is the FluentResults.
We have started to use OneOf like a year ago. We have faced with some of its limitations and ...
                
            
       
        
            
                4
            
            votes
        
        
            
        Separating business logic from data tempts me to use instanceof
                    Is there some other way I have not considered to fix it?
Double dispatch is one way to address this sort of problem.  This is a way to apply inversion of control to get your polymorphic objects to ...
                
            
       
        Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
business-logic × 182architecture × 28
mvc × 23
business-rules × 23
design × 21
domain-driven-design × 19
design-patterns × 18
c# × 15
database × 15
layers × 11
object-oriented × 10
domain-model × 9
object-oriented-design × 7
validation × 6
business × 6
java × 5
database-design × 5
n-tier × 5
algorithms × 4
unit-testing × 4
.net × 4
asp.net-mvc × 4
orm × 4
separation-of-concerns × 4
logic × 4
 
         
         
         
         
         
        