Skip to content

Commit

Permalink
✏更新 组合模式
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcaffebabe committed May 27, 2021
1 parent 4102f2e commit ed6e667
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Binary file added assets/屏幕截图 2021-05-27 162917.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions 软件工程/设计模式/结构型模式.md
Expand Up @@ -61,18 +61,20 @@ class RichMenu implements Menu{...}

## 组合

>将对象组合成树形结构的部分-整体层次结构
>将对象组合成树形结构的部分-整体层次结构,使得客户使用单个对象或组合对象都有一致性

![](https://images.cnblogs.com/cnblogs_com/ywqu/Design%20pattern/Composite%20Pattern/Composit_Pattern_Structure.jpg)
![屏幕截图 2021-05-27 162917](/assets/屏幕截图%202021-05-27%20162917.png)

```java
class Person{
String name;
Phone phone;
//...
}
interface Route {
Route segement1, segement2;
} // 路线
class NationalHighway implements Route{} // 国道
class CountryRoad implements Route {} // 乡道
```

组合模式很重要的一点就是客户端使用所有节点的方式都相同,同时这些节点内部又以组合的方式组合其他节点。

## 装饰器

> 给一个对象添加额外的职责
Expand Down

0 comments on commit ed6e667

Please sign in to comment.