mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-29 23:23:43 +00:00
Update 设计模式 - 生成器.md
小节标题改为中文,重新绘制类图,补充参考资料。
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 170 KiB |
+11
-10
@@ -1,15 +1,12 @@
|
||||
## 5. 生成器(Builder)
|
||||
|
||||
### Intent
|
||||
|
||||
### 意图
|
||||
封装一个对象的构造过程,并允许按步骤构造。
|
||||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/db5e376d-0b3e-490e-a43a-3231914b6668.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
### 类图
|
||||
<div align="center"> <img src="pics/dp-builder.png" width="760px"/> </div><br>
|
||||
|
||||
### 实现
|
||||
以下是一个简易的 StringBuilder 实现,参考了 JDK 1.8 源码。
|
||||
|
||||
```java
|
||||
@@ -76,14 +73,18 @@ public class Client {
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
```text
|
||||
abcdefghijklmnopqrstuvwxyz
|
||||
```
|
||||
|
||||
### JDK
|
||||
|
||||
### JDK 中的应用
|
||||
- [java.lang.StringBuilder](http://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html)
|
||||
- [java.nio.ByteBuffer](http://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html#put-byte-)
|
||||
- [java.lang.StringBuffer](http://docs.oracle.com/javase/8/docs/api/java/lang/StringBuffer.html#append-boolean-)
|
||||
- [java.lang.Appendable](http://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html)
|
||||
- [Apache Camel builders](https://github.com/apache/camel/tree/0e195428ee04531be27a0b659005e3aa8d159d23/camel-core/src/main/java/org/apache/camel/builder)
|
||||
|
||||
## 参考资料
|
||||
|
||||
- 弗里曼. Head First 设计模式 [M]. 中国电力出版社, 2007.
|
||||
- Gamma E. 设计模式: 可复用面向对象软件的基础 [M]. 机械工业出版社, 2007.
|
||||
|
||||
Reference in New Issue
Block a user