6
I am modeling the sales part of my system and came across the following situation. I created a register of payment methods and payment method MONEY is standard and cannot be changed, deleted, etc. I use this form of payment in cash opening for example. I create this form of payment in the installation of the application.
The system allows the user to create new forms of payment according to the need. These new forms of payment may be amended.
How I should treat this situation?
I must add a property in the Formapayment class that enables the class to be deleted and changed?
class FormaPagamento {
private Boolean podeSerAlterado;
}
I must make a check whenever an operation is done and if it is MONEY prohibit the operation?
Should I remove the options to change any form of payment and just allow new forms of payment to be created? Having the option to enable and disable payment methods.
class FormaPagamento {
private Boolean ativo;
}
[ EDITED ]
This is my class diagram for payment methods.
When the user registers the form of payment I display the options for him to register which payment conditions he wants to make available, type 2 x no interest on VISA card would be a condition with 2 installments, 30 days of recurrence and first installment in 30 days.
In the case of the form of payment MONEY i have a default condition that is On Demand, however the user may want to register a new condition for payment on MONEY. So I kept this form of payment in the register and not hardcoded.
I don’t know if it should be a matter of knowing the form of payment itself whether it can be changed or not. I believe that the creation of a service responsible for carrying out the modification of forms of payment would be a more uncoupled way of resolving this. This service would check which form of payment is being modified and would fail if it were a form that should not be modified. This could be a hardcoded rule in your application.
– Fuad Saud
It is an alternative. I had not considered this option, but in case I can only perform this work in the service if I consider it a rule of the application and not the correct domain?
– Robson Coutinho
Good placement; in a way this knowledge is part of the domain itself and perhaps removing this responsibility from it can create problems in how interactions with the domain happen. I confess that I do not know exactly what pattern the practices of DDD advocate in this case, but I will do a research because I found an interesting problem.
– Fuad Saud
Yes it is an interesting problem and even occurs in other parts of the system, in case some accounts of the plan of accounts also can not be changed. But this is only a problem because I refer to such objects by description. In the case of the payment method MONEY, I search the repository for the repository description.
– Robson Coutinho
Not everything in life is a register. There are types of entities that exist only in the code and not in the database. If the business rule is trivial, leave the register at the bank and do not worry about preventing the customer from deleting "money" - it is only him to register again. If the system is more complex, each form of payment has unique behaviors and relationships that cannot be defined only by its attributes in the bank, in these cases the entity is hard coded and is not registered in the bank (eventually some of its attributes are registered, but not the entity itself).
– Caffé