|
22 | 22 | <!-- End Jekyll SEO tag -->
|
23 | 23 |
|
24 | 24 |
|
25 |
| - <link rel="stylesheet" href="/projects/pattern-pigeon/assets/css/style.css?v=c4c261036850ca91f7d009f41bd1456e0b85e27b"> |
| 25 | + <link rel="stylesheet" href="/projects/pattern-pigeon/assets/css/style.css?v=23c80bc9737920d0fc7c4f1bc0d8c1127d473ae5"> |
26 | 26 | <script src="/projects/pattern-pigeon/assets/js/scale.fix.js"></script>
|
27 | 27 | <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
28 | 28 |
|
@@ -73,7 +73,11 @@ <h1 id="coo-coo-salutations">Coo coo! (Salutations!)</h1>
|
73 | 73 | </li>
|
74 | 74 | <li><a href="#composite" id="markdown-toc-composite">Composite</a> <ul>
|
75 | 75 | <li><a href="#what-is-the-composite-pattern" id="markdown-toc-what-is-the-composite-pattern">What is the Composite pattern?</a></li>
|
76 |
| - <li><a href="#what-are-examples-of-the-composite-pattern" id="markdown-toc-what-are-examples-of-the-composite-pattern">What are examples of the Composite pattern?</a></li> |
| 76 | + <li><a href="#what-are-examples-of-the-composite-pattern" id="markdown-toc-what-are-examples-of-the-composite-pattern">What are examples of the Composite pattern?</a> <ul> |
| 77 | + <li><a href="#image-editor" id="markdown-toc-image-editor">Image editor</a></li> |
| 78 | + <li><a href="#sec" id="markdown-toc-sec">SEC</a></li> |
| 79 | + </ul> |
| 80 | + </li> |
77 | 81 | <li><a href="#why-use-the-composite-pattern" id="markdown-toc-why-use-the-composite-pattern">Why use the Composite pattern?</a></li>
|
78 | 82 | <li><a href="#what-disadvantages-are-there-with-the-composite-pattern" id="markdown-toc-what-disadvantages-are-there-with-the-composite-pattern">What disadvantages are there with the Composite pattern?</a></li>
|
79 | 83 | </ul>
|
@@ -155,19 +159,31 @@ <h3 id="composite">Composite</h3>
|
155 | 159 |
|
156 | 160 | <h4 id="what-is-the-composite-pattern">What is the Composite pattern?</h4>
|
157 | 161 |
|
158 |
| -<p>TODO</p> |
| 162 | +<p>The Composite pattern is a structural design pattern used to represent tree-like hierarchies of objects. It allows individual objects (leaves) and groups of objects (composites) to be treated uniformly through a shared interface.</p> |
| 163 | + |
| 164 | +<p>In this pattern, there is a Component interface that both individual elements and composite groups implement. A Composite class contains child components—both leaves and other composites—and delegates all world to them.</p> |
159 | 165 |
|
160 | 166 | <h4 id="what-are-examples-of-the-composite-pattern">What are examples of the Composite pattern?</h4>
|
161 | 167 |
|
162 |
| -<p>TODO</p> |
| 168 | +<h5 id="image-editor">Image editor</h5> |
| 169 | + |
| 170 | +<p>Imagine an image editor that defines a <code class="language-plaintext highlighter-rouge">Graphic</code> interface. The smallest drawable element could be a <code class="language-plaintext highlighter-rouge">Dot</code>, which implements this interface. More complex shapes like <code class="language-plaintext highlighter-rouge">Circle</code> or <code class="language-plaintext highlighter-rouge">CompoundGraphic</code> (which may group multiple <code class="language-plaintext highlighter-rouge">Graphic</code> objects) also implement the same interface. This way, the editor can handle single elements and groups of elements in the same way, such as drawing, moving, or deleting them.</p> |
| 171 | + |
| 172 | +<h5 id="sec">SEC</h5> |
| 173 | + |
| 174 | +<p>The SEC is a great real-world example of the Composite pattern. The conference as a whole can be thought of as a composite object that contains multiple components. These components can be either teams (composite) or players (leaves).</p> |
| 175 | + |
| 176 | +<p>Each player represents a leaf node, an individual unit that does not contain other components. A team represents a composite node containing multiple players and can perform operations like listing player stats, or calculating team rankings. The entire conference could be a composite that contains all teams. Operations like “print all team rosters” or “compute average team performance” can be delegated down through the structure.</p> |
| 177 | + |
| 178 | +<p>Because both teams and players adhere to a common interface (such as <code class="language-plaintext highlighter-rouge">displayStats()</code> or <code class="language-plaintext highlighter-rouge">getRanking()</code>), clients can treat them uniformly. Whether the component is a single player or an entire team, the operation is invoked the same way.</p> |
163 | 179 |
|
164 | 180 | <h4 id="why-use-the-composite-pattern">Why use the Composite pattern?</h4>
|
165 | 181 |
|
166 |
| -<p>TODO</p> |
| 182 | +<p>The Composite pattern is useful when you need to work with tree-like structures where individual objects and groups of objects should be treated the same way. The uniformity of the components and compositions make things simple for clients. It also makes it really easy to scale the tree structure by adding new leaves without changing existing code. It also decouples the client from differentiating between dealing with a single object or a composite, making things simpler!</p> |
167 | 183 |
|
168 | 184 | <h4 id="what-disadvantages-are-there-with-the-composite-pattern">What disadvantages are there with the Composite pattern?</h4>
|
169 | 185 |
|
170 |
| -<p>TODO</p> |
| 186 | +<p>While the Composite pattern is powerful, there are some disadvantages. It can be complex to design, as a component that works for both simple and composite elements can be challenging to make. It’s also hard to restrict behavior because all components share the same interface.</p> |
171 | 187 |
|
172 | 188 | <h3 id="observer">Observer</h3>
|
173 | 189 |
|
|
0 commit comments