Skip to content

Commit 2bb2134

Browse files
committed
Update README.md
1 parent 675b2f1 commit 2bb2134

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

composite/README.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,34 @@ tags:
99
---
1010

1111
## Intent
12-
Compose objects into tree structures to represent part-whole
13-
hierarchies. Composite lets clients treat individual objects and compositions
14-
of objects uniformly.
12+
13+
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients
14+
treat individual objects and compositions of objects uniformly.
1515

1616
## Explanation
1717

1818
Real world example
1919

20-
> Every sentence is composed of words which are in turn composed of characters. Each of these objects is printable and they can have something printed before or after them like sentence always ends with full stop and word always has space before it
20+
> Every sentence is composed of words which are in turn composed of characters. Each of these
21+
> objects is printable and they can have something printed before or after them like sentence always
22+
> ends with full stop and word always has space before it.
2123
2224
In plain words
2325

2426
> Composite pattern lets clients treat the individual objects in a uniform manner.
2527
2628
Wikipedia says
2729

28-
> In software engineering, the composite pattern is a partitioning design pattern. The composite pattern describes that a group of objects is to be treated in the same way as a single instance of an object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies. Implementing the composite pattern lets clients treat individual objects and compositions uniformly.
30+
> In software engineering, the composite pattern is a partitioning design pattern. The composite
31+
> pattern describes that a group of objects is to be treated in the same way as a single instance of
32+
> an object. The intent of a composite is to "compose" objects into tree structures to represent
33+
> part-whole hierarchies. Implementing the composite pattern lets clients treat individual objects
34+
> and compositions uniformly.
2935
3036
**Programmatic Example**
3137

32-
Taking our sentence example from above. Here we have the base class and different printable types
38+
Taking our sentence example from above. Here we have the base class `LetterComposite` and the
39+
different printable types `Letter`, `Word` and `Sentence`.
3340

3441
```java
3542
public abstract class LetterComposite {
@@ -102,7 +109,7 @@ public class Sentence extends LetterComposite {
102109
}
103110
```
104111

105-
Then we have a messenger to carry messages
112+
Then we have a messenger to carry messages:
106113

107114
```java
108115
public class Messenger {
@@ -143,7 +150,7 @@ public class Messenger {
143150
}
144151
```
145152

146-
And then it can be used as
153+
And then it can be used as:
147154

148155
```java
149156
var orcMessage = new Messenger().messageFromOrcs();
@@ -153,13 +160,16 @@ elfMessage.print(); // Much wind pours from your mouth.
153160
```
154161

155162
## Class diagram
163+
156164
![alt text](./etc/composite.urm.png "Composite class diagram")
157165

158166
## Applicability
167+
159168
Use the Composite pattern when
160169

161-
* you want to represent part-whole hierarchies of objects
162-
* you want clients to be able to ignore the difference between compositions of objects and individual objects. Clients will treat all objects in the composite structure uniformly
170+
* You want to represent part-whole hierarchies of objects.
171+
* You want clients to be able to ignore the difference between compositions of objects and
172+
individual objects. Clients will treat all objects in the composite structure uniformly.
163173

164174
## Real world examples
165175

0 commit comments

Comments
 (0)