|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
[zt]J2EE Related design patterns discussed worldheart (rolled technical)
J2EE design patterns related discussion
J2EE design patterns associated orderly discussion :
Worldheart for : (rolled technical)
Sequence :
Design model, the concept is now everywhere, which means we have estimated, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, in the book " Design Patterns-Element of Re-Useable Object-Oriented Software, "this book. According to the statement, three, the type of building, structure and mode of behavior-based model. A total of 23 models, including, to name a few examples here. Practical application, we are not digested and absorbed in a short period of time off, because the model itself is a common thing, we rely on the experience of the past usage. Accustomed to time to train, to shape, so we should not rush to use all modes, but there must be an awareness of the project and began to study the use of several to see and study pattern will bring to you what is the value. But if you are interested in Java JDK1.4 source used in the design mode, can be downloaded from the official website! This place elaborate http://www.javaresearch.org/dn.jsp.
Before entering the topic, I would like to declare that the article no commercial purpose, which involves some of the source code of open source software, related to intellectual property rights, will be used for commercial purposes if the individual is not responsible for the area. Here only for study and exchange. Thank you for your cooperation.
, Then continue to look down.
However, problems arose, specifically how these models were used for Java Project? Indeed the beginning of a headache. On one hand, we need to know the pattern applicable occasions and introduced to the system model, good or bad, and so on that we need to consider. The other hand, the mode of understanding digestion and absorption. Furthermore, your boss forces you to complete the task-:). And so on. In fact, the cool-headed analysis that is not possible. We in the project, to complete his work is one thing, but to consider their own careers to making Java Coder, Java Developer, Java Architect, or what do : : These are basic skills.
Scholars, 1 +1 is liked and what such a simple issue. . . . Derived from theory, as technical workers, for instance, we see the results of the technical nature for real. And we designed the study process, often from the practice, the UML was designed to look at the map (To tell the truth, we are not very good right UML knowledge, it is estimated that less for the UP. ), There is a pattern of what intentions, alias motivation, applicability, structure, participants, in collaboration results achieved, code examples. . . . . . . Heads were dizzy off. You to forget this GP, originally abstract, with so many rules, the word "depressed." Let us start from the analysis results GP code is very, very good, I was such a learning process. We must now look at an example. State type of behavior, for example. (Mode in the network, there are a lot of examples. Java also achieved a lot, for example, Together ControlCenter built on the inside of this template-based GP programming, the details of which we use. Know. )
As we all know, the State seeks to allow an object to changes in its internal state to change its behavior. He looks like the type of the object changes. We look at http://www.javacoder.net/patterns.jsp provided by the State GOF SOFTWARE DESIGN PATTERNS CATALOG FOSS model to achieve.
First look adapter category State.java
State (public interface
Public void handle ();
}
Packaging and Conext adapter to a definition (code wait statement. ), A specific condition related behavior.
Then, the realization adapter category. One is that ConcreteState1.java
Public class ConcreteState1 implements State --
Public void handle () (
System.out.println ( "ConcreteState1.handle () executing");
}
}
Secondly, ConcreteState2.java
Public class ConcreteState2 implements State --
Public void handle () (
System.out.println ( "ConcreteState2.handle () executing");
}
}
These two classes of the State adapter.
Then again, how will Context.java three. Java documents linked.
Public class Context --
Public static final int STATE_ONE = 0
Public static final int STATE_TWO = 1;
4003rd attention, and this is very important, the pattern of irregularities!
State currentState = new private ConcreteState1 ();
Public void request () (
CurrentState.handle ();
}
Public void changeState (int state) (
Switch (state) (
STATE_ONE case :
CurrentState = new ConcreteState1 () ;// key points
Break;
STATE_TWO case :
CurrentState = new ConcreteState2 () ;// key points
Break;
}
}
}
Thus, finished four. Java documents, the fact you have achieved the State design pattern is very interesting, right? It is just that simple.
Look at how to use the model of the design. Write a Client.java see.
Public class Client --
Public static void main (String[] args) (
4003rd tectonic Context
Context ctx = new Context ();
4003rd arouse Context.request ()
Ctx.request ();
4003rd changes ctx state? Why the change? We think about.
Ctx.changeState (Context.STATE_TWO);
4003rd reminded once again Context.request (), the results will be quite different.
Ctx.request ();
}
}
Is it your wish to try? Look at their own operations should know about.
An analysis is completed, the State would know how clever model is a "grafting", or otherwise, and so on the can.
This is a step in the analysis of the model has not yet completed, you return to the best textbooks, and then looking at, if you look at the pattern there, I think I wrote a failure!
Simplifying complicated! ! ! ! ! |
[zt]J2EE Related design patterns discussed worldheart (rolled technical)
Then, in an excellent article on the state model. . . :) |
[zt]J2EE Related design patterns discussed worldheart (rolled technical)
Simple words, terrific! |
| |