Home computickets Business logic, what is it?

Business logic, what is it?

Author

Date

Category

The MVC pattern describes an easy way to build the structure of an application,
the purpose of which is to separate business logic from
user interface . As a result, the application is easier to scale, test, maintain, and of course implement.

Source

It is not entirely clear what this term means


Answer 1, authority 100%

Business logic is the logic of the domain model – everything that happens in your application in terms of the domain.

For example, on SO, these are all actions with users, questions, answers, pros, cons, etc.

Example:

  1. If the user has not typed ZZZ reputation – send his edit for review by other participants – this is business logic, it belongs in the model.

  2. Redirecting the user to the question page after creating it is non-business logic, which should be in the controller.

  3. Hide the “Leave a comment” button if the current user does not have the right to leave comments – especially the presentation of data (flag from the model) – in the view.

MVC allows you to highlight the “non-business” logic associated with the user interface:

  • calls to model methods for specific user actions
  • show / hide controls
  • preparing data for sending to the client.

… and put the presentation logic in a separate piece of the application – Controller.

thus leaving the “pure” business logic in the model, not tied to the user interface.


It’s worth noting that the link in the question leads to an article illustrated with a Classic MVC diagram. In reality, the Web uses a more modern version of the pattern – MVC Model2 – and its derivatives. Its difference is that the View does not interact directly with the model.

Interaction in modern MVC looks like this:

 enter image description here


Answer 2, authority 62%

Business logic is the same as domain / domain / application domain logic. Let’s say you are programming software for an animal shelter and an orphanage.

According to the business logic of an animal shelter, suppose a cat that has not been taken by new owners in a week needs to be euthanized. Before that, he must be fed, watered and put to bed.

According to the business logic of the orphanage – the child must be fed, watered and put to bed. You cannot stick a syringe with a lethal dose of morphine into it.

In this case, all data structures, algorithms, etc. – in the two programs are almost the same. Except for this little detail.

“THIS ONE IFCHIK decided the FATE OF THE KOTEYKA”, or, for example, “the novice programmer KILLED the baby with a VECTOR”

If you confuse the business logic of an animal shelter and an orphanage, and euthanize a child, and give a kitten a doll, I hope you will find yourself in a mess, there they will tell you everything about OOP.

It doesn’t matter if it’s business, calculating the configuration of molecules, shelter or ship management. Business logic is the part that should work correctly and reliably in the end, the part that the customer (kitten, child) is waiting for the results

If you do not separate, let’s say, the interface from the business logic, then instead of pressing the “give the child to new parents” or “put the kitten to sleep” button, on two neat – almost similar – control panels (interfaces) you you will run back and forth, trying to figure out who to drown, who to put to sleep, who to give to new parents and why nothing works.

You have not separated the interface (the control panel for launching kittens to the moon) from the business logic and everything is confused.

Well, I warned you.

You use singletons, queues, databases, flat files, microservices – it doesn’t matter – it is important that the business logic works correctly.

correct means correct results at acceptable time. The rest of your customers are not interested. As long as they are not yours.

That is why you can sell very bad – from the point of view of a programmer – software to customers, but you can hardly build a reliable system on it. Business logic requirements can be and are met, but this code is not possible

P.S. A small historical excursion.
This is called business logic because in the Normal World, in the Outer Empire, programming in commerce and corporations has been developing since the 50s-60s: banks, insurance agencies, tour operators, medicine.

Ie you were paid to implement the requirements of a particular business

It’s good that this is business logic, not party logic, as in North Korea.


Answer 3, authority 35%

This is logic that considers the task in terms of the real world, a specific business. That is, it can be a progressive taxation scale (namely, a description of how it is formed and what comes of it), the principles of invoicing, the distribution of employee salary ratios, but not the procedure for connecting files in the engine, not adjusting the load balancing: these are our problems, not business.


Answer 4, authority 4%

Read business logic as simple as logic . Everything.

And its separation from UI means: that the view should not have any calls to the database, selections from it, auxiliary functions on N-lines, for example, clever sorting, filtering, data structuring; data encryption; checking for the correctness of the login / password and any other extra manipulations with data.

The view should display the final result that will come in response to a request to the managing class, and all data manipulation (as described above) (logic ) should take place elsewhere.


The end.


Answer 5

For example, you have a directory of phone numbers application.
Depending on the country code, you will use a particular display format. You will store in the database without formatting (to improve indexing and search). So, you can pull the numbers straight from the base and format the display of the phone number in View . But it is best to create a (business layer) layer that will be engaged in pulling from the base and formatting (which is called business logic ), and transferring it to the View … You need to clearly understand that View is a presentation, it shows what we will give, and not in our own way.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions