[Design Modes] One code extraction function actually uses 3 design modes, the aircraft is too large to pull
The manager of Dubi came to Egan again for help
Egan took this job and looked at his dwindling hair
There are close to one hundred Dao interface classes. Is this work done by humans?
How to move this, it needs a crane, should I build it myself?
Suddenly Egan had a flash of inspiration: Then I will build a crane myself
First write a script to copy the Dao interface to the basic service module. The witty Egan thought of directly using DOS commands to migrate.
First, you need to create the target directory (mkdir command), and then execute the copy command, which is probably like this
After thinking about it, one by one execution was slow in the past, so let's write a program.
Egan conceived the main components:
Copy Dao interface and Dao.xml to the corresponding basic service module
Copy entity classes (dto, entyty, etc.) to the corresponding data interface service module
Analyze the Dao interface to remove internal impurities to obtain the DataServiceIntf interface and save it to the data interface service module
Analyze the Dao interface to remove the internal impurity solution; the analytic method gets the parameters and turns the abstract method into a concrete method, and calls Dao's corresponding method internally. Save to the basic service module class name XXXDataService
That's almost it, after classification, it becomes three categories:
Copy files without parsing
Need to parse and process
Files that do not need to be processed (used to match the above 4 components)
In this way, an interface class and three abstract methods are abstracted
Then the Dao interface classes, Dao.xml, and entities are directly copied. The difference here is that the path of the target file is different. Then you can write a moderate abstract class to abstract the target file path.
The interface and abstract class are almost written, and then all the classes are created first. The class diagram is almost like this
Write Dao file processor implementation class
Write entity file processor implementation class
Perfect, the copy method is finished like this.
Like, Dao transfer DataServiceIntf has also been written
Egan continues to write the remaining classes
The preparation is complete.
Finally, only the startup class is left, and the file traversal processing is required
Tick tick
The writing is finally finished
Start a try. All successfully processed.
Completed the task in less than a day, hahaha, brag about it, celebrate, and have dinner tonight
Hee hee, I won’t tell the manager of Dubi today that it’s finished, just take a dip, and tell him that it’s finished tomorrow, let him give him a wave of rewards.
Tick tick
the next day
Egan was so happy, he secretly said: If you have a snack, you should come more.
What design patterns do you think Egan used to write this set of components? You can leave a message below.
Popular articles in the past:
☞[Design Mode] The plane is too big and Egan can’t move
☞[Design Pattern-Prototype] Egan finally came to raise the salary opportunity
☞[Design Mode] The manager of Funny Bi asked Egan to chat
☞[Design Mode] Swear not to stay up late
☞ The server suddenly crashes and restarts causing redis in docker to fail to start
☞ How does jdbc sql solve dictionary table data conversion efficiently and elegantly?