auto commit

This commit is contained in:
CyC2018 2018-06-05 10:12:43 +08:00
parent f62e387200
commit a3dc8be2fa
2 changed files with 50 additions and 1 deletions

View File

@ -38,6 +38,8 @@
拥有设计模式词汇,在沟通时就能用更少的词汇来讨论,并且不需要了解底层细节。
[源码以及 UML 图](https://github.com/CyC2018/Design-Pattern-Java)
# 二、创建型
## 1. 单例Singleton
@ -523,7 +525,54 @@ abcdefghijklmnopqrstuvwxyz
### 意图
使用原型实例指定要创建对象的类型;通过复制这个原型来创建新对象。
使用原型实例指定要创建对象的类型,通过复制这个原型来创建新对象。
### 类图
<div align="center"> <img src="../pics//a40661e4-1a71-46d2-a158-ff36f7fc3331.png"/> </div><br>
### 实现
```java
public abstract class Prototype {
abstract Prototype myClone();
}
```
```java
public class ConcretePrototype extends Prototype {
private String filed;
public ConcretePrototype(String filed) {
this.filed = filed;
}
@Override
Prototype myClone() {
return new ConcretePrototype(filed);
}
@Override
public String toString() {
return filed;
}
}
```
```java
public class Client {
public static void main(String[] args) {
Prototype prototype = new ConcretePrototype("abc");
Prototype clone = prototype.myClone();
System.out.println(clone.toString());
}
}
```
```html
abc
```
### JDK

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB