As a programmer, the design pattern is becoming increasingly popular. the attention of the net community. This change is very gratifying. the Java Community is ahead of us, but this situation may change one day.
Talking about 23 Java design modes from the perspective of MM1. FACTORY-try to catch up with MM. The chicken
resources are accessed at most one thread at any time. The Java language implements a full object in multithreaded programming and provides good support for synchronization mechanisms. There are four methods in Java that support synchronization, the first three of which are synchronous methods, and one is the pipe method.
(1) Wait ()/Notify () method
(2) await ()/signal () method
(3) Blockingqueue blocking
This article continues to introduce23 Design Mode Seriesmode of responsibility chain. What is a chain1, chain is a series of nodes of the collection. 2. Each node of the chain can be flexibly split and re-reorganized.Responsibility Chain ModelEnables multiple objects to have the opportunity to process the request, thereby avoiding the coupling between the sender and the recipient of the request, connecting the object to a chain, and passing the reques
The concept of MVC can be found in Baidu encyclopedia.
MVC is a framework design mode for web development. It achieves logical separation, robustness, and scalability between page design and background processing (a lot of good words can be used ).
MVC can be used in Java Web projects. More development is needed. Peopl
I saw this article in the Java Forum. The author compared the 32 Java models in a simple language, which has a good inspiration, but unfortunately I didn't give a specific meaning, I added it to the back. These are the simplest introductions. If you want to learn them, I suggest you take a look at Dr. Yan Hong's book "Java and patterns.
Creation Mode
1. Factory-t
The observer, like a person, is interested in a lot of things, like music, electronics, Game, stock and so on, these things change can arouse the attention of enthusiasts and always pay attention to them. In the code. We also have this kind of way to design some interesting ideas. Write a demo today to describe this idea, using Java's built-in observer to implement this idea.Well, the program ape is not ver
[eg: it is something that is a trade-off between some serialization classes and Targe (ENUM. Constants). If you apply a specialized interface, use the former]
Method
Check the validity of the parameter [method at the beginning of the parameter check, the parameters to be trusted to make a credible judgment]
Protective copy when necessary [output to the client, the data returned by the client is not necessarily trustworthy, if possible, a copy on the server side, which is the m
(realsubjecti realsubjecti) { This. Realsubjecti =Realsubjecti; } @Override Public voidBuykole () {//TODO here can do a lot of things and even decide not to do buy CokeRealsubjecti.buykole (); System.out.println ("A good mood for an ice cream."); }}/***/Publicclassimplements isubject{ @Override publicvoid buykole () { System.out.println ("Go to buy Coke");} }/***/Publicclass Test {publicstatic void Main (string[] args) {
unchanged, the client program will not have the slightest change, will not bring a move and lead the whole body of the disaster, This is the embodiment of good encapsulation. But if you use Concreteproduct and concretecreator two classes directly, you can't do it anyway. Excellent object-oriented design encourages the use of encapsulation (encapsulation) and delegates (delegation) , and the factory method pattern is a typical example of encapsulation
the entire container, if the container is high concurrency operation, will result in a sharp decrease in operational performance.The advantage of the second option is that the concurrent containers under the concurrent package are typically highly optimized for performance, guaranteeing high concurrency scenarios, but the disadvantage is that the implementation of these containers is relatively complex, and the use of the scene has a certain limit, generally only guarantee the weak consistency
considerations:
You can only use the method provided by a singleton class to get a singleton object, do not use reflection, or you will instantiate a new object.
Do not break a single instance class object from a static reference in a class to a dangerous operation.
Multithreading uses a single example when using shared resources, attention to thread-safety issues.
Some controversies about the single case pattern in Java:
Objects i
Java Design pattern Learning 06--static agent and dynamic proxy
First, the agent mode
Provides an agent for an object to control access to this agent. The proxy class and the delegate class have a common parent or parent interface, so that proxy class object substitution can be used wherever the delegate class object is used. The proxy class is responsible for the preprocessing of the request, filtering, a
know as little as possible about other objects.Basic idea: reduce coupling.g: the principle of synthetic multiplexingInstead of using inheritance, it is preferable to use a combination rather than an inheritance principle, which is to use the composition/aggregation method first.Basic idea: In taking advantage of the object's lowest point, the combination is preferred, not the inheritance, because any changes to the parent class can directly affect the behavior of the subclass.eg. To pack an el
, click the Submit button to determine the password change;5. Click on the top right button, select Exit System, select OK to exit the system, there is a successful exit system interface;Second, user feedback:1, the lack of return keys, it is difficult to return to the previous step to view the previous operation;2, no open user registration function;3, the interface is not beautiful;Third, the user recommends:1, open user registration function;2, beautify the interface, optimize the operation,
I. What is a singleton modeIn this case, we should consider the design of the singleton mode only if you want to keep one object at a time and you do not want to have more objects.The primary function of Singleton mode is to ensure that only one instance of a class exists in a Java program.The singleton pattern has many advantages, it can avoid the repetition creation of the instance object, not only can re
A singleton object (Singleton) is a common design pattern. In Java applications, singleton objects guarantee that only one instance of the object exists in a JVM. There are several benefits to this model:1, some classes are created more frequently, for some large objects, this is a lot of overhead. 2,eliminate the new operator, reduce the use of system memory fre
correctly by the system. 9, do not write some meaningless queries, such as the need to generate an empty table structure: Select Col1,col2 into #t from T where 1=0 such code will not return any result set, but will consume system resources, Should be changed to this: Create TABLE #t (") 10, a lot of times with exists instead of in is a good choice: Select num from a where num in (select num from B) Replace with the following statement: Select Num fro
Java Open source Fresh e-commerce platform-search module design and architecture (source code can be downloaded)Description: The search module is aimed at the buyer's users, looking for food products to find a very strenuous query. Currently, it is also a fast search product.For mobile app buyer users, the required speed is completed in 3 seconds. Support fuzzy query, due to business combat surface, the ent
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.