Skip to content

Commit 040e29f

Browse files
author
github-actions
committed
Auto-deploy from Pattern Pigeon: 23c80bc9737920d0fc7c4f1bc0d8c1127d473ae5 thatrobotdev/Pattern-Pigeon-website@23c80bc
1 parent e36055e commit 040e29f

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

content/projects/pattern-pigeon/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<!-- End Jekyll SEO tag -->
2323

2424

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">
2626
<script src="/projects/pattern-pigeon/assets/js/scale.fix.js"></script>
2727
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
2828

content/projects/pattern-pigeon/index.html

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<!-- End Jekyll SEO tag -->
2323

2424

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">
2626
<script src="/projects/pattern-pigeon/assets/js/scale.fix.js"></script>
2727
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
2828

@@ -73,7 +73,11 @@ <h1 id="coo-coo-salutations">Coo coo! (Salutations!)</h1>
7373
</li>
7474
<li><a href="#composite" id="markdown-toc-composite">Composite</a> <ul>
7575
<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>
7781
<li><a href="#why-use-the-composite-pattern" id="markdown-toc-why-use-the-composite-pattern">Why use the Composite pattern?</a></li>
7882
<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>
7983
</ul>
@@ -155,19 +159,31 @@ <h3 id="composite">Composite</h3>
155159

156160
<h4 id="what-is-the-composite-pattern">What is the Composite pattern?</h4>
157161

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>
159165

160166
<h4 id="what-are-examples-of-the-composite-pattern">What are examples of the Composite pattern?</h4>
161167

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>
163179

164180
<h4 id="why-use-the-composite-pattern">Why use the Composite pattern?</h4>
165181

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>
167183

168184
<h4 id="what-disadvantages-are-there-with-the-composite-pattern">What disadvantages are there with the Composite pattern?</h4>
169185

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>
171187

172188
<h3 id="observer">Observer</h3>
173189

content/projects/pattern-pigeon/index.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,31 @@ While the Strategy pattern offers flexibility, there are also a few trade-offs.
6161

6262
#### What is the Composite pattern?
6363

64-
TODO
64+
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.
65+
66+
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.
6567

6668
#### What are examples of the Composite pattern?
6769

68-
TODO
70+
##### Image editor
71+
72+
Imagine an image editor that defines a `Graphic` interface. The smallest drawable element could be a `Dot`, which implements this interface. More complex shapes like `Circle` or `CompoundGraphic` (which may group multiple `Graphic` 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.
73+
74+
##### SEC
75+
76+
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).
77+
78+
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.
79+
80+
Because both teams and players adhere to a common interface (such as `displayStats()` or `getRanking()`), clients can treat them uniformly. Whether the component is a single player or an entire team, the operation is invoked the same way.
6981

7082
#### Why use the Composite pattern?
7183

72-
TODO
84+
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!
7385

7486
#### What disadvantages are there with the Composite pattern?
7587

76-
TODO
88+
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.
7789

7890
### Observer
7991

0 commit comments

Comments
 (0)