Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e354649

Browse files
author
deeper
committed
prototype summary
1 parent b364d0e commit e354649

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.ruoxu.pattern.prototype;
2+
3+
/**
4+
* 原型模式
5+
* 知识点(浅拷贝和深拷贝)
6+
* 浅拷贝:仅拷贝对象本身(一些基本类型的变量和String[特殊]),而不拷贝对象包含的引用,如同 new object(int yes,string yes,Object no);
7+
* 深拷贝:不仅拷贝对象本身,而且拷贝对象包含的基本变量和引用变量。(开发中建议使用深拷贝而不使用浅拷贝)
8+
* 使用场景:如果类的初始化(构造函数)需要消耗很大的资源,如数据,硬件资源等,通过原型模式减少消耗,如果创建类的成本很小,那么就没必要使用此模式,直接new。
9+
* 使用方法:要让实例调用clone方法就需要让此类实现Cloneable接口(同Serializable类似,Cloneable接口只是个标签接口,不含任何方法),一般如果你的子类没有特殊需要而重写clone()方法就直接用super.clone() 就行了(原因略)。
10+
* 注意事项:原型模式是在内存中二进制流的拷贝,要比直接new性能要好得多,但是正因如此,构造函数是不会执行的。
11+
* @author Administrator
12+
*
13+
*/
14+
public class Demo {
15+
public static void main(String[] args) {
16+
17+
}
18+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /