Parameters for business rules registered in the database

Asked

Viewed 62 times

0

Good night,

Recently I came across a situation that left me very in doubt, is a module of a system that calculates the value to be paid for a service and for this all rules are expressed in a table in the database, for examples let’s imagine the table below.

inserir a descrição da imagem aqui

Let’s imagine that there are many rules that are registered and that these are parameters to verify if the amount to be paid for the service is entire or only half, I want the opinion on how you would implement such a case.

What’s been on my mind ?

Implement a Rewrite object calculation and in the calculation method of the Service object it would receive as parameter the Rewrite calculation, example:

$servico = new Servico(etc...);
$valorServico = $servico->calcularPagamento($regraDeCalculo);
//$regraDeCalculo consegue consultar o banco em busca da regra específica para o serviço

I’m really lost already I appreciate any help.

1 answer

0


Expressing business rules in columns of a table in the database is not a good practice. If you need to change something in the rule, you will have to change the structure of your bank and it will probably break your code.

I believe you’re going the right way. I would sort the rules by type into one class by piece, with methods with a single responsibility each, so that if you need to change something, you will only need to change one or another line of code.

  • Thank you very much, you took away my doubt.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.