<p>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) consists of logic that is related to the business requirements..</p>

<p>Can anyone tell me what exactly consists of business logic? How can it be distinguished from other code? Is there some simple test to determine what is business logic and what is not?</p>

[{'answer_id': 39293, 'author': 'Serhat Ozgel', 'author_id': 31505, 'author_profile': 'https://Stackoverflow.com/users/31505', 'pm_score': 7, 'selected': True, 'text': '<p>Simply define what you are doing in plain English. When you are saying things businesswise, like "make those suffer", "steal that money", "destroy this portion of earth" you are talking about business layer. To make it clear, things that get you excited go here.</p>\n\n<p>When you are saying "show this here", "do not show that", "make it more beautiful" you are talking about the presentation layer. These are the things that get your designers excited.</p>\n\n<p>When you are saying things like "save this", "get this from database", "update", "delete", etc. you are talking about the data layer. These are the things that tell you what to keep forever at all costs.</p>\n'}, {'answer_id': 39294, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 0, 'selected': False, 'text': '<p>For me, " <em>business logic</em> " makes up all the entities that represent data applicable to the problem domain, as well as the logic that decides on "what do do with the data"..</p>\n\n<p>So it should really consist of "data transport" (not access) and "data manipulation".. Actually data access (stuff hitting the DB) should be in a different layer, as should presentation code.</p>\n'}, {'answer_id': 39299, 'author': 'Eugene Yokota', 'author_id': 3827, 'author_profile': 'https://Stackoverflow.com/users/3827', 'pm_score': 0, 'selected': False, 'text': '<p>If it contains anything about things like form, button, etc.. it\'s not a business logic, it\'s presentation layer. If it contains persistence to file or database, it\'s DAL. Anything in between is business logic. In reality, anything non-UI sometimes gets called "business logic," but it should be something that concerns the problem domain, not house keeping.</p>\n'}, {'answer_id': 39315, 'author': 'Lars Mæhlum', 'author_id': 960, 'author_profile': 'https://Stackoverflow.com/users/960', 'pm_score': 2, 'selected': False, 'text': '<p>I dont like the BLL+DAL names of the layers, they are more confusing than clarifying.<br>\nCall it DataServices and DataPersistence. This will make it easier.  </p>\n\n<p>Services manipulate, persistence tier CRUDs (Create, Read, Update, Delete)</p>\n'}, {'answer_id': 39319, 'author': 'Aidan Ryan', 'author_id': 1042, 'author_profile': 'https://Stackoverflow.com/users/1042', 'pm_score': 0, 'selected': False, 'text': '<p>Business logic is pure abstraction, it exists independent of the materialization/visualization of the data in front of your user, and independent of the persistence of the underlying data.</p>\n\n<p>For example, in Tax Preparation software, one responsibility of the business logic classes would computation of tax owed.  They would not be responsible for displaying reports or saving and retrieving a tax return.</p>\n\n<hr>\n\n<p>@Lars, "services" implies a certain architecture.</p>\n'}, {'answer_id': 39330, 'author': 'roomaroo', 'author_id': 3464, 'author_profile': 'https://Stackoverflow.com/users/3464', 'pm_score': 4, 'selected': False, 'text': '<p>It\'s probably easier to start by saying what <em>isn\'t</em> business logic. Database or disk access isn\'t business logic. UI isn\'t business logic. Network communications aren\'t business logic.</p>\n\n<p>To me, business logic is the rules that describe how a business operates, not how a software architecture operates. Business logic also has a tendency to change. For example, it may be a business requirement that every customer has a single credit card associated with their account. This requirement may change so that customers can have several credit cards. In theory, this should just be a change to the business logic and other parts of your software will not be affected.</p>\n\n<p>So that\'s theory. In the real world (as you\'ve found) the business logic tends to spread throughout the software. In the example above, you\'ll probably need to add another table to your database to hold the extra credit card data. You\'ll certainly need to change the UI.</p>\n\n<p>The purists say that business logic should always be completely separate and so would even be against having tables named "Customers" or "Accounts" in the database.\nTaken to its extreme you\'d end up with an incredibly generic, impossible to maintain system.</p>\n\n<p>There\'s definitely a strong argument in favour of keeping most of your business logic together rather than smearing it throughout the system, but (as with most theories) you need to be pragmatic in the real world.</p>\n'}, {'answer_id': 39333, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': 3, 'selected': False, 'text': "<p>To simplify things to a single line...<br>\nBusiness Logic would be code that doesn't depend on/won't change with a specific UI/implementation detail.. \nIt is a code-representation of the rules, processes, etc. that are defined by/reflect the business being modelled.</p>\n"}, {'answer_id': 39680, 'author': 'Marcio Aguiar', 'author_id': 4213, 'author_profile': 'https://Stackoverflow.com/users/4213', 'pm_score': 3, 'selected': False, 'text': '<p>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:</p>\n\n<p>"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)</p>\n\n<p>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.</p>\n\n<p>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 <a href="http://martinfowler.com/articles/dblogic.html" rel="noreferrer">here</a>. </p>\n'}]
['https://Stackoverflow.com/questions/39288', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/184/']