single case design pattern
A singleton design pattern is to ensure that a class has and only one instance exists and provides an access point for global access, an instance that can be accessed by all programs.
It is generally used in this case: when you want to use a class, you need to use an instance of the class, and new to create the instance of the program will cause a waste of resources, and the more instances are not easy to control. Different threads can cause different steps when they are invoked.
Cases in which a single case pattern is used in actual development: Database connection Pool Windows Task Manager (Task Manager), cannot open the second task Manager most of the music player website counters Windows recycle Bin (Recycle Bin) is also a typical single case application. The Recycle Bin maintains only one instance of the system during its operation. Factory design mode
First, the factory method pattern is a substitute for a new object, so it can be used where all the objects need to be generated, but careful consideration should be given to adding a factory class to manage and increasing the complexity of the code.
second, when flexible, scalable frameworks are needed, the factory approach model can be considered. Everything is the object, and everything is also the product class, such as the need to design a framework for connecting mail servers, there are three network protocols to choose from: POP3, IMAP, HTTP, we can use these three connection methods as product classes, define an interface such as Iconnectmail, Then define the operation of the message, three specific product classes (that is, the connection method) for different implementations, and then define a factory method, according to different incoming conditions, select a different connection mode. So designed, can do a perfect extension, such as some mail server provides the WebService interface, very good, we just add a product class on it.
again, the factory method pattern can be used in heterogeneous projects, for example, through WebService with a non-Java project, although WebService claims to be able to achieve the isomorphism of heterogeneous systems, but in the actual development, still encounter many problems, such as type problems, WSDL file support issues, and so on, the objects generated from the WSDL are considered to be a product and then managed by a specific factory class to reduce coupling with the perimeter system.
Finally, you can use the framework of test-driven development, for example, to test a Class A, which requires that Class B, which has an association with Class A, also be generated, and we can use the factory method pattern to virtualize Class B to avoid coupling Class A with Class B. At present, due to the birth of Jmock and Easymock, the use of the scene has been weakened, readers can be encountered in this situation directly consider the use of Jmock or Easymock.
Agent design mode
Here's a very powerful analogy. I'm not going to stick around. Adapter Mode Power Converter analogy Monk example