Home > Back-end >  The actual use of Java strategy pattern
The actual use of Java strategy pattern

Time:09-16

For example, a common strategy pattern implementation: computer executed according to the different mobile hardware to read data, print the result of the different
The code below:
 

MobileHardwareInterface flashDisk=new flashDisk ();
Computer computerA=new Computer (flashDisk);

MapDisk MapDisk=new MapDisk ();
Computer computerB=new Computer (mapDisk);

ComputerA. UsbRead ();
ComputerB. UsbWrite ();


The computer is the outer container, contains a MobileHardwareInterface member variable, MobileHardwareInterface UsbRed and UsbWrite both methods
And then there are two falslDisk fulfillment MobileHardwareInterface mapDisk are classes, print the result of the different inside, this is a simple strategy pattern using


Now the real problem is that I have a lot of different types of reports are subject to approval by the administrator, make a report interface, and then report their implementation methods of examination and approval, the strategy pattern is such,
But the problem is my object of this report is through the front desk or database query, namely new out a new object, but the execution method there are plenty of other service with mapper object of injection, I write that there is no problem?
I mean, more than one object in a pile of @ Autowrie singleton then agent to generate a new singleton object, feeling a little problem about this?? I don't know why I always feel so strange, as it is new every time a lot of agents to generate new wouldn't it be worse?


CodePudding user response:

Every time you put it inside the cache is no need to set up a create next time
  • Related