C
C
ChelFeb2015-09-25 10:37:22
Java
ChelFeb, 2015-09-25 10:37:22

How to maintain consistency between two pieces of code in an application that duplicate business logic?

There is a problem, in a java project with some MVC framework, there are two places with duplication of user saving logic. The specifics of the application is such that And with a further change in the controller, either the order of saving or adding new / deleting user fields, you need to somehow maintain consistency in the controller and in the audit manager.
1) An audit of changes in the state (fields) of the user is carried out when saving. At what at it it is a lot of child objects.
2) And the state of the user is restored from this audit.
3) When restoring, you need to take into account the order of calling methods, performing some additional actions, such as sending an email message about creation.
The main problem in supporting this functionality is that the user is stored in two places 1) In the controller from the bean with data received from the client. 2) From audit to audit manager.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
protven, 2015-09-25
@ChelFeb

Refactor. For example, move this functionality to some separate place and pull it from your two services.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question