In recent projects, data Access objects, templates, and command patterns have been used. The feeling has a good effect on the improvement of the structure. The IF branch structure of the controller is improved with the command mode, and the action code is simplified to two lines.
One problem is that the controller is not able to do unit tests and has to simplify the code as much as possible.
Do you have any good experience?
Recommend a good book: refactoring and Patterns.
Reply content:
In recent projects, data Access objects, templates, and command patterns have been used. The feeling has a good effect on the improvement of the structure. The IF branch structure of the controller is improved with the command mode, and the action code is simplified to two lines.
One problem is that the controller is not able to do unit tests and has to simplify the code as much as possible.
Do you have any good experience?
Recommend a good book: refactoring and Patterns.
There is no absolutely good, sometimes you will be in this time more in favor of a design pattern, think it is the world's most perfect design mode, this is the only one of your life, you will be tempted to praise it, always hanging in the mouth.
But maybe next project you will forget it completely. You say these also belong to the scope of the program structure, my experience is not at the beginning of the project to focus on the construction, so you will continue to struggle with the original code can not extricate themselves, I believe that we have heard a programmer to change the story of the code, the superior let a programmer add a function, and finally the programmer to rewrite the other people's Things I want to measure whether a programmer's maturity is a sign that he can suppress the impulse at the right time.
As you said the controller can not test the problem, I think there is no. But this has to be an invitation to QA to answer.
The inability to unit test, most likely due to the strong dependency in different layers, and the way the dependencies are not elegant and messy, makes it impossible for you to easily replace this dependency for unit testing.
You said the controller is not good unit testing, I guess it should be because of the data persistence layer caused, the master MF recommended is a domain model to solve this dependency problem, but will increase the complexity of the project, this is the need for architecture adjuster tradeoff point!