This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| design_pattern:composite_pattern [2017/10/29 12:57] – ledyx | design_pattern:composite_pattern [2021/02/07 03:25] (current) – [Composite Pattern] ledyx | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| = Composite Pattern = | = Composite Pattern = | ||
| - | 그릇과 내용물을 동일시해서 재귀적인 구조 구축. | + | 그릇(<fc red> |
| - | {{tag> | + | * <fc red>Tree 구조의 Data(= 재귀적)</ |
| + | * File System | ||
| + | * Test Case 3개가 있을 때, 이를 모두 합쳐서 Test하고 싶은 경우 | ||
| + | * GUI 프로그래밍에서 View안에 자식 View를 갖는 경우 | ||
| + | |||
| + | {{tag> | ||
| = Component = | = Component = | ||
| Line 62: | Line 67: | ||
| 그릇. 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 { | ||
| Line 82: | Line 87: | ||
| } | } | ||
| + | /* Directory와 File을 같은 내용물로 간주 */ | ||
| public Entry add(Entry entry) { | public Entry add(Entry entry) { | ||
| directory.add(entry); | directory.add(entry); | ||
| Line 120: | Line 126: | ||
| } | } | ||
| } | } | ||
| + | |||
| + | |||
| + | /* | ||
| + | /root (3) | ||
| + | /root/bin (2) | ||
| + | / | ||
| + | / | ||
| + | /root/tmp (0) | ||
| + | /root/usr (0) | ||
| + | */ | ||
| </ | </ | ||