[Design Modes] One code extraction function actually uses 3 design modes, the aircraft is too large to pull

[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

1.png


2.png

3.png


4.png

 

Egan took this job and looked at his dwindling hair

70d688367a131d0008b3a3292dd92cb2.png5.png

There are close to one hundred Dao interface classes. Is this work done by humans?

 6.png

bef4400cbc05de35bf684369d9db10ed.gif

 

How to move this, it needs a crane, should I build it myself?

7.pngbef4400cbc05de35bf684369d9db10ed.gif

Suddenly Egan had a flash of inspiration: Then I will build a crane myself8.png

7271c5355849581ab0cc4a422170bbb4.png

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

9.png

da0ee77761bb7faddda2580e5b9834c3.png

After thinking about it, one by one execution was slow in the past, so let's write a program.

 

Egan conceived the main components:

  1. Copy Dao interface and Dao.xml to the corresponding basic service module

  2. Copy entity classes (dto, entyty, etc.) to the corresponding data interface service module

  3. Analyze the Dao interface to remove internal impurities to obtain the DataServiceIntf interface and save it to the data interface service module

  4. 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:

  1. Copy files without parsing

  2. Need to parse and process

  3. 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

f3ad9200a444b787a52825d7289193a9.png10.png

 

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.

11.pngbef4400cbc05de35bf684369d9db10ed.gif

The interface and abstract class are almost written, and then all the classes are created first. The class diagram is almost like this

12.pngbef4400cbc05de35bf684369d9db10ed.gif

 

Write Dao file processor implementation class

13.pngb214fd19867ad4e94d5db9e281c8b5c5.png

 

Write entity file processor implementation class

14.pngbef4400cbc05de35bf684369d9db10ed.gif

Perfect, the copy method is finished like this.

8f3bee0dca960401693944813c5f5110.png

bef4400cbc05de35bf684369d9db10ed.gif15.png

3e05762d1d9d2602b922c71f299d86d6.png

15.5.png

16.png

Like, Dao transfer DataServiceIntf has also been written

Egan continues to write the remaining classes

640.gif8e6d1cc6e43e3b27f84b8e037e863cb0.png

The preparation is complete.

 

Finally, only the startup class is left, and the file traversal processing is required

Tick ​​tick

640.gif

bef4400cbc05de35bf684369d9db10ed.gif

The writing is finally finished

17.pngbef4400cbc05de35bf684369d9db10ed.gif

09e177d93182ef6d9363616cd159070b.png

18.png

Start a try. All successfully processed. 

Completed the task in less than a day, hahaha, brag about it, celebrate, and have dinner tonight

19.pnga39728de7edab09a6154ef999d5c17b9.png

 

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.20.png

182b412ad3db5fb4fdd0f7c9c4369f7d.png

Tick ​​tick

640.gif

the next day


21.png

22.png

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?

☞ Introduction to NIO-Buffer

☞ Introduction to NIO-Channel> Direct Buffer

Guess you like

Origin blog.51cto.com/7041393/2554331