Both sides previous revisionPrevious revisionNext revision | Previous revision |
design_pattern:composite_pattern [2017/10/29 12:59] – [Composite Pattern] ledyx | design_pattern:composite_pattern [2021/02/07 03:25] (current) – [Composite Pattern] ledyx |
---|
= Composite Pattern = | = Composite Pattern = |
그릇(복수)과 내용물(단수)을 동일시해서 재귀적인 구조 구축. (ex. Directory Entry) | 그릇(<fc red>복수</fc>)과 내용물(<fc red>단수</fc>)을 동일시(= 혼합물, Composite)해서 재귀적인 구조 구축. |
* ex. Test Case 3개가 있을 때, 이를 모두 합쳐서 Test하고 싶은 경우 | |
| |
{{tag>Architecture Modeling DesignPattern Structional}} | * <fc red>Tree 구조의 Data(= 재귀적)</fc> |
| * File System |
| * Test Case 3개가 있을 때, 이를 모두 합쳐서 Test하고 싶은 경우 |
| * GUI 프로그래밍에서 View안에 자식 View를 갖는 경우 |
| |
| {{tag>Architecture Modeling Design_Pattern Structural}} |
| |
= Component = | = Component = |
그릇. Leaf나 Composite 역할을 넣을 수 있음. | 그릇. Leaf나 Composite 역할을 넣을 수 있음. |
| |
<sxh java ; highlight:[20-23]> | <sxh java ; highlight:[4, 21-24]> |
public class Directory extends Entry { | public class Directory extends Entry { |
| |
} | } |
| |
| /* Directory와 File을 같은 내용물로 간주 */ |
public Entry add(Entry entry) { | public Entry add(Entry entry) { |
directory.add(entry); | directory.add(entry); |
} | } |
} | } |
| |
| |
| /* |
| /root (3) |
| /root/bin (2) |
| /root/bin/sub1 (10000) |
| /root/bin/sub2 (20000) |
| /root/tmp (0) |
| /root/usr (0) |
| */ |
</sxh> | </sxh> |