GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update 装饰设计模式.MD · WhCannon/JavaSE@ea4463f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Design-pattern
    • 装饰设计模式.MD
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Design-pattern/装饰设计模式.MD‎

Copy file name to clipboardExpand all lines: Design-pattern/装饰设计模式.MD
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Writer
1717
这时就会发现只为提高功能而进行的继承,会导致继承体系越来越臃肿,不够灵活。
1818
重新思考这个问题?
1919
既然不同的流加入的都是同一种技术--缓冲,上面的方法是让缓冲和每一个具体的对象相结合。那就可以将缓冲进行单独的封装,哪个对象需要缓冲就将哪个对象和缓冲关联(通过构造函数传入需要被关联的对象)
20+
```java
2021
class Buffer{
2122
Buffer(TextWriter w)
2223
{}
@@ -32,5 +33,6 @@ Writer
3233
|--TextWriter:用于操作文本
3334
|--MediaWriter:用于操作媒体。
3435
|--BufferWriter:用于提高Writer效率。
36+
```
3537
装饰比继承灵活。IO流的缓冲区就是用这种思想创建出来的。这种思想可以用到其他的Java体系上。
3638
注意:装饰类和被装饰类都必须所属同一个接口或者父类。

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.