Design pattern, this concept is now flying, we all have estimates in hand, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, in the book ment of re-useable object-oriented Software ", this book. According to the argument, there are three kinds of creation patterns, structural patterns and behavioral patterns. A total of 23 models are included, not listed here. In practical application, we cannot digest and absorb it in a short time, because the model itself is a conventional thing, relying on the past project experience to sum up the customary usage. Habit of time to cultivate, to form, so we do not rush to use all the mode, but must have this awareness, in the project, learning to start using a few to see how the research model will bring you what value. But if you are interested in the design pattern used by Java JDK1.4 Source code, you can download it to the official website!
Before I go to the point, I declare that the article has no commercial purpose, which involves some source code of open source software, so when it comes to intellectual property, if someone uses it for commercial purposes, the individual is not responsible for the responsibility. Only for the purpose of learning and communicating here. Thank you for your cooperation.
But the question is, how do you use these patterns specifically in Java project? It was really a headache at first. On the one hand, we need to know the application of the pattern, the introduction of the model to the system to bring good or bad, and so on we should consider. On the other hand, the model itself understands digestion and absorption. Furthermore, your boss is forcing you to complete the task-: Wait a minute. In fact, it is not impossible to analyze it calmly. We do our job in the project on the one hand, but on the other hand we have to consider our own career, to the Java coder, Java Developer, Java Architect, or whatever ... Doing well, these are basic skills.
Scholars, just like to put 1+1, such a simple question with what .... Theoretical deduction, as a technical worker, for example, we look at the results, the implementation of technology. While we are learning design patterns in the process, often out of practice, to see the design pattern of the UML diagram (to say the truth, everyone's UML skills will not be too good, it used for our up estimate is also less.) And what are the intentions, aliases, motivations, applicability, structure, participants, collaborations, effects, implementations, code instances, .... My head is dizzy. Whether everyone has forgotten, this GP, would have been
is very abstract, plus so many rules, two words, "depressed." We might as well start from the analysis of the GP code is very good, I learn the process is like this. Let's look at an example now. Take the behavior pattern state as an example. (The implementation example of the pattern is a lot on the network.) Java is also a lot of implementations, for example, together ControlCenter inside the built-in GP-based programming template, the details are used to know. )
As you know, state is meant to allow an object to change its behavior when its internal status changes. The object seemed to modify his class. We first look at the http://www.javacoder.net/patterns.jsp provided on the GOF SOFTWARE Design Patterns Catalogue The state mode source code implementation.
First look at the interface class, State.java
public interface State {
public void handle();
}
To define interfaces to encapsulate and Conext (code statement later!) The behavior associated with a particular state.
Then look at the implementation class for the interface. First one, Concretestate1.java.
public class ConcreteState1 implements State {
public void handle() {
System.out.println("ConcreteState1.handle() executing");
}
}
The second one, Concretestate2.java.
public class ConcreteState2 implements State {
public void handle() {
System.out.println("ConcreteState2.handle() executing");
}
}
These two classes implement the State interface.