Reference Documentation:
1. Design mode-the basis of reusable object-oriented software
2.http://www.cnblogs.com/itteacher/archive/2012/12/02/2797857.html (Java Design pattern IV: Prototype mode (Prototype pattern))
Prototype mode (PROTOTYPE) (Create mode)
Theoretical knowledge can be referenced in reference documents;
Look at the format of prototype:
Code implementation:
Mazeprototypefactory.java:
Package com.rick.designpattern.prototype;
/**
* Created by MyPC on 2017/6/22.
*/Public
class Mazeprototypefactory extends Mazefactory {
private Maze _prototypemaze;
Private Wall _prototypewall;
Private _prototyperoom;
Private Door _prototypedoor;
Public Mazeprototypefactory (Maze Maze, Wall Wall, the guest-guest, Door Door) {
this._prototypemaze = Maze;
This._prototypewall = wall;
This._prototyperoom = the hostel;
This._prototypedoor = door;
}
Public Maze Makemaxe () {
return new Maze ();
}
Public Wall Makewall () {
return _prototypewall.clone ();
}
public makeroom (int n) {
return new (n);
}
Public Door Makedoor (guest r1, guest R2) {
Door Door = _prototypedoor.clone ();
Door.initialize (R1, r2);
return door;
}
}
Wall.java:
Package com.rick.designpattern.prototype;
/** *
Wall
* <p>
* Created by MyPC on 2017/6/20.
*/Public
class Wall {public
Wall () {
} public
Wall (Wall other) {
} public
Wall clone () {
return new Wall (this);
}
}
Door.java:
Package com.rick.designpattern.prototype;
/** *
Door
* <p>
* Created by MyPC on 2017/6/20.
*/Public
class Door {
private r1, R2;
Public Door () {
} publicly
Door (Door other) {
r1 = other.r1;
r2 = other.r2;
}
public void Initialize (R1, guest R2) {
this.r1 = r1;
THIS.R2 = r2;
}
Public Door Clone () {
return to new Door (this);
}
Public Door (R1, r2) {
this.r1 = r1;
THIS.R2 = r2;
}
}
Bombedwall.java:
Package com.rick.designpattern.prototype;
/**
* Created by MyPC on 2017/6/20.
*/Public
class Bombedwall extends Wall {
private boolean _bomb;
Public Bombedwall () {
} publicly
Bombedwall (Bombedwall other) {
_bomb = Other._bomb;
}
Public Bombedwall Clone () {
return to new Bombedwall (this);}
}
Client.java:
Package com.rick.designpattern.prototype;
/**
* Created by MyPC on 2017/6/20.
*/Public
class Client {public
static void Main (string[] args) {
mazegame mazegame = new Mazegame ();
Mazeprototypefactory mazeprototypefactory =
new Mazeprototypefactory (New Maze (), New Wall (), new (1), New Door () );
Mazegame.createmaze (mazeprototypefactory);
Mazeprototypefactory MazePrototypeFactory2 =
new Mazeprototypefactory (New Maze (), New Bombedwall (), New Roomwithabomb (1), New Door ());
Mazegame.createmaze (MazePrototypeFactory2);
}
}