File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
java-des/src/com/java/design/prototype Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .java .design .prototype ;
2
+
3
+ public class ConcreatePrototype extends Prototype {
4
+
5
+ public ConcreatePrototype (String name ) {
6
+ setName (name );
7
+ }
8
+
9
+ }
Original file line number Diff line number Diff line change
1
+ package com .java .design .prototype ;
2
+
3
+ public class Prototype implements Cloneable {
4
+
5
+ private String name ;
6
+
7
+ public String getName () {
8
+ return name ;
9
+ }
10
+
11
+ public void setName (String name ) {
12
+ this .name = name ;
13
+ }
14
+
15
+ @ Override
16
+ protected Object clone () throws CloneNotSupportedException {
17
+ return super .clone ();
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ package com .java .design .prototype ;
2
+
3
+ /**
4
+ * 原型模式 -----> 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象
5
+ *
6
+ * @author Administrator
7
+ *
8
+ */
9
+ public class PrototypePattern {
10
+
11
+ public static void main (String [] args ) throws CloneNotSupportedException {
12
+
13
+ Prototype prototype = new ConcreatePrototype ("Folger" );
14
+ Prototype prototype2 = (Prototype ) prototype .clone ();
15
+
16
+ System .out .println (prototype + " " + prototype .getName ());
17
+ System .out .println (prototype2 + " " + prototype2 .getName ());
18
+ }
19
+
20
+ }
You can’t perform that action at this time.
0 commit comments