A very interesting pdf for learning Java Design Patterns

Source: Internet
Author: User

The catalogue is as follows: Describe design patterns in very popular language.

Directory
The 1th Chapter Strategy mode "strategy pattern" .......................................................................................................... 4
The 2nd chapter of proxy pattern "proxy pattern" ............................................................................................................... 8
3rd one-case pattern "SINGLETON pattern" ...................................................................................................... 12
The 4th chapter, "Multition pattern" in multiple cases ...................................................................................................... 16
5th Factory Method Mode "FACTORY pattern" ................................................................................... 19
6th Abstract Factory Model "abstract FACTORY pattern" ................................................................................. 31
7th Chapter Façade Mode "facade pattern" ........................................................................................................... 44
8th Chapter Adapter Mode "ADAPTER pattern" ..................................................................................................... 51
The 9th Chapter Template Method pattern ................................................................................. 63
The 10th Builder pattern "builders pattern" ...................................................................................................... 82
11th Bridge pattern "bridge pattern" ............................................................................................................ 97
12th. Command pattern ................................................................................................... 112
13th Chapter Decoration Mode "DECORATOR pattern" .................................................................................................. 126
14th iterator pattern "ITERATOR pattern" .................................................................................................. 137
15th Chapter "COMPOSITE pattern" in combination mode ................................................................................................... 147
16th Observer pattern "OBSERVER pattern" ................................................................................................. 175
17th chapter of the Chain of responsibility "CHAIN of RESPONSIBILITY pattern" ......................................................................... 194
18th Visitor Pattern "VISITOR pattern" ..................................................................................................... 210
19th Status Mode "state pattern" ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ....... ....... ..... ..... ..... ..... ..... ..... ..... ....... ....... ......... 236
20th prototype pattern "PROTOTYPE pattern" ................................................................................................... 255
21st Chapter "Mediator pattern" of intermediary mode ................................................................................................. 268
22nd. Interpreter Mode "interpreter pattern" ............................................................................................. 286
23rd Chapter Hengyuan Pattern "FLYWEIGHT pattern" .................................................................................................... 287
24th Memorandum Mode "MEMENTO pattern" ................................................................................................. 288
25th Chapter Mode Big PK ......................................................................................................................... .................. 289
The 26th chapter of the six major design principles ......................................................................................................................... ........... 290
26.1 Single Duty principle "RESPONSIBILITY PRINCIPLE" ............................................................................................ 290
26.2 Richter Replacement principle "LISKOV SUBSTITUTION PRINCIPLE" .............................................................................................. 297
Your design pattern
3rd page
26.3 dependency Inversion principle "dependence inversion PRINCIPLE" .......................................................................................... 309
26.4 Interface Isolation principle "INTERFACE segregation PRINCIPLE" .......................................................................................... 310
26.5 Dimitri Law "low of DEMETER" ..................................................................................................................... 320
26.6 Opening and closing principle "OPEN CLOSE PRINCIPLE" .................................................................................................................. 330
The 27th chapter of the Mixed mode explanation ......................................................................................................................... ........... 332
The 28th chapter updates the record: ......................................................................................................................... .............. 334
Related instructions ... ..... ... ..... ..... ..... ..... ..... ..... ...................... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ..... ........................................... 335
Related instructions ... ..... ... ..... ..... ..... ..... ..... ..... ...................... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ..... ........................................... 335
29th Chapter ......................................................................................................................... .......................... 336

The 1th Chapter Strategy mode "strategy pattern"
Liu Bei to the Jiangdong to marry his wife, go before Zhuge Liang to Zhao Yun (best man) Three ace, said is to solve the thorny problem by the secret,
Hey, not to mention, really solved the big problem, get to the end is Zhou Yu accompany the lady and fold soldiers Ah, let's first see what this scene is like
Of
First of all, the elements in this scene: Three ingenious tricks, a brocade sac, a Zhao Yun, the ingenious trick is the small bright comrade to give, the coup is placed in the brocade SAC
, commonly known as an ace, that Zhao Yun is a work of the people, from the capsule to take out a clever idea, execute, and then win, with the Java program
How do you show this? Let's look at the class diagram first:
Three tricks is the same type of dongdong, then we write an interface:
Package com.cbf4life.strategy;
/**
* @author cbf4life [email protected]
* I ' m glad to share my knowledge.
* First to set a policy interface, this is Zhuge Liang to Zhao Yun's three an ace of the interface
*
*/
Public interface IStrategy {
Every trick is an executable algorithm.
public void operate ();
}
Your design pattern
5th page
Then write three implementation classes, there are three clever tricks:
Package com.cbf4life.strategy;
/**
* @author cbf4life [email protected]
* I ' m glad to share my knowledge.
* Find Qiaoguo old help, so that Sun Quan can not kill Liu Bei
*/
public class Backdoor implements IStrategy {
public void operate () {
System.out.println ("Find Qiaoguo old help, let Wu too to Sun Quan Pressure");
}
}
Package com.cbf4life.strategy;
/**
* @author cbf4life [email protected]
* I ' m glad to share my knowledge.
* Ask Wu to open a green light
*/
public class Givengreenlight implements IStrategy {
public void operate () {
SYSTEM.OUT.PRINTLN ("Ask Wu to open a green light, release!") ");
}
}
Package com.cbf4life.strategy;
/**
* @author cbf4life [email protected]
* I ' m glad to share my knowledge.
* Neighbour, block the pursuers.
*/
public class Blockenemy implements IStrategy {
public void operate () {
System.out.println ("neighbour, block the pursuers");
}
}
Well, let's see, three ingenious tricks are there, that need to have a place to put these tricks ah, put the brocade bag:
Package com.cbf4life.strategy;
/**
* @author cbf4life [email protected]
* I ' m glad to share my knowledge.
* There's a trick, there's a bag.
*/
public class Context {
Constructor, you're going to use that ingenious trick.
Private IStrategy straegy;
Public Context (IStrategy strategy) {
This.straegy = strategy;
}
I'm using the trick.
public void operate () {
This.straegy.operate ();
}
}
Then is the Zhao Yun valiantly with three Jin capsule, pulled into the ranks of the elderly, but also want to marry innocent girl, amorous Liu Lao
Ye son to Ruzhui, hey, not to mention, small bright three clever tricks is really good, look:
Package com.cbf4life.strategy;
/**
* @author cbf4life [email protected]
* I ' m glad to share my knowledge.
*/
public class Zhaoyun {
/**
* Zhao Yun appearance, he according to Zhuge Liang to his account, and then disassemble the ingenious plan
*/
public static void Main (string[] args) {
Context context;

When I first came to Wu, I had to dismantle.
System.out.println ("-----------the first-------------when he arrived in the Kingdom of Wu");
Context = new context (new backdoor ()); Get a plan.
Context.operate (); Disassemble execution
System.out.println ("\n\n\n\n\n\n\n\n");
Liu Bei has a very, very reluctant, second one.
System.out.println ("-----------Liu Bei, took a second-------------");
Context = new Context (new Givengreenlight ());
Context.operate (); The second SAC was executed.
System.out.println ("\n\n\n\n\n\n\n\n");
What if the soldiers of Sun Quan are chasing after them? Split the third one.
System.out.println ("-----------Sun Quan's creeps are chasing, what? Split the third one.
-------------");
Context = new Context (new Blockenemy ());
Context.operate (); Neighbour Retreat
System.out.println ("\n\n\n\n\n\n\n\n");
/*
* The problem is: Zhao Yun actually do not know is that strategy ah, he only know to dismantle the first bag,
* And do not know is backdoor this ingenious idea, how to do? It seems that this strategy model has already written out the name of the stratagem.
*
Wrong Backdoor, Givengreenlight, Blockenemy is just a code, you write first, second,
Third, no one will say you're wrong!
*
* The advantage of the strategy model is that it embodies the characteristics of cohesion-poly-low coupling, the disadvantage, this one, I go back and check
*/
}
}
On this three strokes, make the week Lang is "accompany the lady and fold soldiers" Ah! This is the strategy mode, cohesion the characteristics of low-coupling is also shown,
Another is extensibility, which is the OCP principle, the strategy class can continue to increase, as long as the modification of Context.java, which
Not much to say, I understand it.

Specific link to meet Baidu Network disk: Http://pan.baidu.com/s/1bnvZebH Extract code: KZH6

A very interesting pdf for learning Java Design Patterns

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.