Recently, data access objects, templates, and command modes were used in the project. I feel that it has played a very good role in improving the structure. The command mode improves the if branch structure of the controller, and the action code is simplified to two lines. One problem currently is that controllers cannot perform unit tests, so we have to simplify the generation as much as possible. in recent projects, we have used data access objects, templates, and command modes. I feel that it has played a very good role in improving the structure. The command mode improves the if branch structure of the controller, and the action code is simplified to two lines.
One problem currently is that the controller cannot perform unit tests, so we have to simplify the code as much as possible.
Do you have any good experience?
We recommend a good book: restructuring and model.
Reply content:
Recently, data access objects, templates, and command modes were used in the project. I feel that it has played a very good role in improving the structure. The command mode improves the if branch structure of the controller, and the action code is simplified to two lines.
One problem currently is that the controller cannot perform unit tests, so we have to simplify the code as much as possible.
Do you have any good experience?
We recommend a good book: restructuring and model.
It is not absolutely easy to use. sometimes you will love a design pattern during this period and think it is the most perfect design pattern in the world. this is the only one in your life, you can't help but boast about it.
But maybe you will forget it for the next project. What you said is still in the scope of program structure. my experience is that you should not think about refactoring at the beginning of the project, so that you will constantly struggle with the original code and cannot extricate yourself, I believe everyone has heard of the story of a programmer's code change. The Superior asked a programmer to add a function. Finally, the programmer directly overwrites others. I want to measure whether a programmer is mature, that is, whether he can suppress this impulse at the right time.
As for the problem that the controller you mentioned cannot be tested, I think it does not exist. However, we have to invite QA to answer this question.
Unit testing is not possible because the dependencies on different layers are too strong and the dependency generation method is not elegant enough and messy. as a result, you cannot easily replace this dependency for unit testing.
What you are talking about is that the controller cannot perform a good unit test. I guess it is because of the data persistence layer. master MF recommends the domain model to solve this dependency problem well, however, it will increase the complexity of the project. this is a point that architects need to weigh!