Skip to content

Commit 242b4bc

Browse files
committed
merge main to resolve README conflict with batch-11
# Conflicts: # patterns/12-data-storage/README.md # patterns/14-testing/README.md
2 parents 2659ad3 + a3ac3fe commit 242b4bc

19 files changed

Lines changed: 367 additions & 285 deletions

File tree

‎patterns/01-design-patterns-gof/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Origin. Gamma, Helm, Johnson, Vlissides 1994
44

5-
32 entries, 306,354 words, 1 more planned, 33 total when the family is complete. Every entry carries all 18
5+
32 entries, 306,348 words, 1 more planned, 33 total when the family is complete. Every entry carries all 18
66
dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
77

88
## Behavioral
@@ -15,7 +15,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
1515
| [Iterator](iterator.md) | canonical | 11,672 | A client needs to visit every element of a collection, and the collection knows how it stores those elements while the client does not and should not. |
1616
| [Mediator](mediator.md) | canonical | 11,878 | A set of objects has to cooperate, and every one of them needs to know something about the others in order to do its part. |
1717
| [Memento](memento.md) | canonical | 11,628 | An object holds state that changes over time, and something outside that object needs the ability to put the state back the way it was. |
18-
| [Observer](observer.md) | canonical | 13,321 | A piece of state changes, and an unknown number of other pieces of the system need to react. |
18+
| [Observer](observer.md) | canonical | 13,315 | A piece of state changes, and an unknown number of other pieces of the system need to react. |
1919
| [Servant](servant.md) | contested | 5,677 | Wikipedia's own definition, quoted directly. |
2020
| [State](state.md) | canonical | 14,281 | An object behaves differently depending on a mode it is in, and every method that depends on that mode has grown the same conditional. |
2121
| [Strategy](strategy.md) | canonical | 11,071 | An object does a piece of work in more than one way, and the choice of way is not a property of the object's identity. |

‎patterns/01-design-patterns-gof/observer.md‎

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -286,28 +286,43 @@ leak possible, and the two facts are the same fact.
286286
## 6. ASCII structure diagram
287287

288288
```
289-
+--------------------------------+ +----------------------+
290-
| Subject | holds | Observer |
291-
|--------------------------------| 0..* |----------------------|
292-
| - observers: List<Observer> |--------->| + update(subject?) |
293-
| + attach(o): Registration | +----------------------+
294-
| + detach(reg) | ^ ^
295-
| # notify() | | |
296-
+--------------------------------+ | |
297-
^ | |
298-
| extends implements | | implements
299-
| | |
300-
+--------------------------------+ +--------------------+---------+
301-
| ConcreteSubject | reads | ConcreteObserverA | ...B |
302-
|--------------------------------|<- - - - -|--------------------|----------|
303-
| - state: State | (pull) | - subject: ref | - cache |
304-
| + getState(): State | | + update(...) | + update |
305-
| + setState(s) -> notify() | +--------------------+----------+
306-
+--------------------------------+
307-
308-
Solid arrow = compile time dependency.
309-
Dashed arrow = the pull model back reference. Absent in the push model.
310-
The Registration returned by attach() is the only thing that can detach.
289+
+-----------------------------+
290+
| Subject |
291+
| - observers: List<Observer> |
292+
| + attach(o): Registration |
293+
| + detach(reg) |
294+
| # notify() |
295+
+-----------------------------+
296+
| holds 0..*
297+
v
298+
+--------------------+
299+
| Observer |
300+
| + update(subject?) |
301+
+--------------------+
302+
303+
+----------------------------------+
304+
| ConcreteSubject, extends Subject |
305+
| - state: State |
306+
| + getState(): State |
307+
| + setState(s) -> notify() |
308+
+----------------------------------+
309+
| reads (pull), dashed back reference
310+
v
311+
+----------------------------------------+
312+
| ConcreteObserverA, implements Observer |
313+
| - subject: ref |
314+
| + update(...) |
315+
+----------------------------------------+
316+
+----------------------------------------+
317+
| ConcreteObserverB, implements Observer |
318+
| - cache |
319+
| + update |
320+
+----------------------------------------+
321+
322+
Solid arrow means a compile-time dependency. Dashed
323+
arrow is the pull model's back reference, absent in the
324+
push model. The Registration returned by attach() is
325+
the only thing that can detach.
311326
```
312327

313328
## 7. Dynamics

‎patterns/02-code-smells/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Origin. Fowler and Beck, Refactoring
44

5-
28 entries, 221,153 words. Every entry carries all 18
5+
28 entries, 221,119 words. Every entry carries all 18
66
dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
77

88
## Bloaters
@@ -11,7 +11,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
1111
|---|---|---|---|
1212
| [Data Clumps](data-clumps.md) | canonical | 5,832 | The smell shows up first in method signatures. |
1313
| [Duplicate Code](duplicate-code.md) | canonical | 8,029 | The same idea is written down twice, or more, in a codebase, so that changing the idea means finding and editing every copy. |
14-
| [Large Class](large-class.md) | canonical | 9,844 | A class keeps absorbing new fields and new methods until it is doing the job of what should have been five or six separate collaborators. |
14+
| [Large Class](large-class.md) | canonical | 9,817 | A class keeps absorbing new fields and new methods until it is doing the job of what should have been five or six separate collaborators. |
1515
| [Lazy Class](lazy-class.md) | canonical | 7,708 | A codebase accretes classes over time for reasons that have nothing to do with present-day need. |
1616
| [Long Method](long-method.md) | canonical | 7,675 | A method starts small. It does one clear thing, and its name says what that thing is. |
1717

@@ -28,7 +28,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
2828
| Pattern | Maturity | Words | Intent |
2929
|---|---|---|---|
3030
| [Comments](comments.md) | canonical | 8,795 | A comment is a message from one point in time to a later reader, and it is never checked by anything that runs. |
31-
| [Dead Code](dead-code.md) | canonical | 9,473 | Dead code accumulates as an ordinary, unavoidable byproduct of change. |
31+
| [Dead Code](dead-code.md) | canonical | 9,466 | Dead code accumulates as an ordinary, unavoidable byproduct of change. |
3232
| [Long Parameter List](long-parameter-list.md) | canonical | 7,502 | A function, method, or constructor accumulates parameters over its lifetime, usually one at a time, usually each addition individually reasonable, until the call site becomes ... |
3333
| [Loops](loops.md) | canonical | 8,826 | A loop is the most flexible construct available in an imperative language. |
3434
| [Middle Man](middle-man.md) | canonical | 7,237 | The smell shows up during evolution, almost never at the moment a class is first written. |

‎patterns/02-code-smells/dead-code.md‎

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -270,41 +270,46 @@ indistinguishable, to the next reader, from a claim that happens to be wrong.
270270
## 6. ASCII structure diagram
271271

272272
```
273-
REACHABILITY GRAPH
274-
===================
275-
276-
entry points live subgraph dead subgraph
277-
------------- -------------- -------------
278-
279-
main() ----+ +--> handleOrder() applyLegacyDiscount()
280-
| | | (no incoming edge
281-
httpRoute +---> dispatch() -+--> applyTax() from any entry
282-
/orders | | point below)
283-
| +--> validate()
284-
cronJob |
285-
nightly +---> reconcile()-+--> readLedger() [dead subgraph has
286-
| zero paths back
287-
+--> writeLedger() to any entry point]
288-
289-
290-
GUARD-GATED BRANCH
291-
===================
292-
293-
process(order)
294-
|
295-
v
296-
+---------------------------+
297-
| if legacyFlag.isEnabled() | <-- legacyFlag hardcoded false
298-
| doLegacyPath(order) | in every environment since
299-
| else | the rollout finished
300-
| doCurrentPath(order) |
301-
+---------------------------+
302-
| |
303-
v v
304-
doLegacyPath doCurrentPath <-- structurally reachable,
305-
(dead: guard (live: the practically dead, needs the
306-
never true) only path guard's known value as evidence,
307-
taken) not the call graph alone
273+
REACHABILITY GRAPH
274+
275+
Entry points: main(), httpRoute /orders, cronJob nightly
276+
277+
main() and httpRoute /orders both call dispatch(), which
278+
calls:
279+
handleOrder()
280+
applyTax()
281+
validate()
282+
283+
cronJob nightly calls reconcile(), which calls:
284+
readLedger()
285+
writeLedger()
286+
287+
This is the live subgraph, every function above has a path
288+
back to an entry point.
289+
290+
Dead subgraph: applyLegacyDiscount(). No incoming edge from
291+
any entry point above, zero paths back to any entry point.
292+
293+
294+
GUARD-GATED BRANCH
295+
296+
process(order)
297+
|
298+
v
299+
if legacyFlag.isEnabled():
300+
doLegacyPath(order)
301+
else:
302+
doCurrentPath(order)
303+
304+
legacyFlag is hardcoded false in every environment since the
305+
rollout finished.
306+
307+
doLegacyPath: dead, guard never true.
308+
doCurrentPath: live, the only path actually taken.
309+
310+
doLegacyPath is structurally reachable but practically dead,
311+
needs the guard's known value as evidence, not the call
312+
graph alone.
308313
```
309314

310315
## 7. Dynamics

‎patterns/02-code-smells/large-class.md‎

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -275,46 +275,51 @@ to update in the same commit that performs the split.
275275
## 6. ASCII structure diagram
276276

277277
```
278-
Before, one class, several unrelated responsibility clusters:
279-
280-
+--------------------------------------------------+
281-
| Order |
282-
|----------------------------------------------------|
283-
| - lineItems, customerId, discountCode | cluster A: pricing
284-
| - taxRate, currency |
285-
| - shippingAddress, billingAddress | cluster B: fulfillment
286-
| - trackingNumber, carrier |
287-
| - emailTemplate, smtpConfig | cluster C: notification
288-
| - auditLog | cluster D: audit
289-
|----------------------------------------------------|
290-
| + calculateSubtotal() | cluster A methods
291-
| + applyDiscount() |
292-
| + calculateTax() |
293-
| + scheduleShipment() | cluster B methods
294-
| + assignCarrier() |
295-
| + sendConfirmationEmail() | cluster C methods
296-
| + sendShippingNotice() |
297-
| + recordAuditEntry() | cluster D methods
298-
+--------------------------------------------------+
299-
300-
After, Extract Class applied per cluster, Original Class delegates:
301-
302-
+--------------+ uses +-------------------+
303-
| Order | ------------> | OrderPricer |
304-
| (core state) | | (cluster A logic) |
305-
+--------------+ +-------------------+
306-
| uses +-------------------------+
307-
+--------------> | ShipmentScheduler |
308-
| | (cluster B logic) |
309-
| +-------------------------+
310-
| uses +-------------------------+
311-
+--------------> | OrderNotifier |
312-
| | (cluster C logic) |
313-
| +-------------------------+
314-
| uses +-------------------------+
315-
+--------------> | OrderAuditLog |
316-
| (cluster D logic) |
317-
+-------------------------+
278+
Before, one class, several unrelated responsibility
279+
clusters:
280+
281+
+---------------------------------------------+
282+
| Order |
283+
| cluster A, pricing: lineItems, customerId, |
284+
| discountCode, taxRate, currency |
285+
| cluster B, fulfillment: shippingAddress, |
286+
| billingAddress, trackingNumber, carrier |
287+
| cluster C, notification: emailTemplate, |
288+
| smtpConfig |
289+
| cluster D, audit: auditLog |
290+
| |
291+
| cluster A methods: calculateSubtotal(), |
292+
| applyDiscount(), calculateTax() |
293+
| cluster B methods: scheduleShipment(), |
294+
| assignCarrier() |
295+
| cluster C methods: sendConfirmationEmail(), |
296+
| sendShippingNotice() |
297+
| cluster D methods: recordAuditEntry() |
298+
+---------------------------------------------+
299+
300+
After, Extract Class applied per cluster, Original
301+
Class delegates:
302+
303+
+--------------------+
304+
| Order (core state) |
305+
+--------------------+
306+
| uses
307+
v
308+
+-------------------------------+
309+
| OrderPricer (cluster A logic) |
310+
+-------------------------------+
311+
+-------------------------------------+
312+
| ShipmentScheduler (cluster B logic) |
313+
+-------------------------------------+
314+
+---------------------------------+
315+
| OrderNotifier (cluster C logic) |
316+
+---------------------------------+
317+
+---------------------------------+
318+
| OrderAuditLog (cluster D logic) |
319+
+---------------------------------+
320+
321+
Order uses all four, each handling one cluster's
322+
logic.
318323
```
319324

320325
## 7. Dynamics

‎patterns/05-architectural/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Origin. Buschmann POSA 1, Bass SEI
44

5-
31 entries, 248,953 words. Every entry carries all 18
5+
31 entries, 248,937 words. Every entry carries all 18
66
dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
77

88
## Architectural
@@ -30,7 +30,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
3030
| [Multi-Tenant Architecture](multi-tenant-architecture.md) | canonical | 5,015 | A SaaS provider serves many customers, called tenants, from one running application. |
3131
| [Onion Architecture](onion-architecture.md) | canonical | 8,637 | A team builds a business application against a specific database, a specific web framework, and a specific set of third party integrations, because those are the concrete ... |
3232
| [Peer-to-Peer](peer-to-peer.md) | canonical | 8,950 | A system needs many participants to exchange data or share work, and at least one of the following forces makes a single, dedicated server the wrong place to put that coordination. |
33-
| [Pipeline Architecture](pipeline-architecture.md) | canonical | 8,757 | A system needs to transform a stream of data through a sequence of independent processing steps, and the set of steps, their order, or their implementation is expected to change ... |
33+
| [Pipeline Architecture](pipeline-architecture.md) | canonical | 8,741 | A system needs to transform a stream of data through a sequence of independent processing steps, and the set of steps, their order, or their implementation is expected to change ... |
3434
| [Pipes and Filters](pipes-filters.md) | canonical | 7,891 | A system must transform a stream of data through several independent processing steps, and the set of steps, their order, or the data source itself is expected to change over the ... |
3535
| [Plugin Architecture](plugin-architecture.md) | canonical | 7,823 | An application needs to support a set of behaviours that is open-ended, unknown at the time the core is built, and likely to be supplied by parties who are not the core's own ... |
3636
| [Plugin Sandbox](plugin-sandbox.md) | established | 10,826 | A host application defines an extension point, using Plugin Architecture or Microkernel, so that its behavior can grow without every new feature being merged into the core ... |

‎patterns/05-architectural/pipeline-architecture.md‎

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -271,29 +271,54 @@ survives in a variable called pipeline.
271271
## 6. ASCII structure diagram
272272

273273
```
274-
DATA SOURCE DATA SINK
275-
(file, socket, (file, socket,
276-
queue, request) queue, response)
277-
| ^
278-
v |
279-
+-----------+ pipe +-----------+ pipe +-----------+
280-
| FILTER A |------------->| FILTER B |------------->| FILTER C |
281-
| (e.g. | [buffer, | (e.g. | [buffer, | (e.g. |
282-
| parse) | backpress] | enrich) | backpress] | encode) |
283-
+-----------+ +-----------+ +-----------+
284-
^ ^ ^
285-
| | |
286-
single input, single input, single input,
287-
single output single output single output
288-
(uniform contract (uniform contract (uniform contract
289-
shared by every shared by every shared by every
290-
filter in the chain) filter in the chain) filter in the chain)
291-
292-
Optional PUMP drives passive filters that have no thread of their own.
293-
294-
+------+ calls A(x) +---+ calls B(A(x)) +---+ calls C(B(A(x)))
295-
| PUMP |--------------->| A |------------------->| B |------------------> out
296-
+------+ +---+ +---+
274+
+--------------------------------------------+
275+
| Data Source (file, socket, queue, request) |
276+
+--------------------------------------------+
277+
| single input/output uniform contract
278+
v
279+
+----------------------------+
280+
| Filter A, e.g. parse |
281+
| pipe, buffer, backpressure |
282+
+----------------------------+
283+
|
284+
v
285+
+----------------------------+
286+
| Filter B, e.g. enrich |
287+
| pipe, buffer, backpressure |
288+
+----------------------------+
289+
|
290+
v
291+
+-----------------------+
292+
| Filter C, e.g. encode |
293+
+-----------------------+
294+
|
295+
v
296+
+-------------------------------------------+
297+
| Data Sink (file, socket, queue, response) |
298+
+-------------------------------------------+
299+
300+
Every filter shares the same uniform contract, single
301+
input, single output.
302+
303+
Optional PUMP drives passive filters that have no
304+
thread of their own:
305+
306+
+------+
307+
| PUMP |
308+
+------+
309+
| calls A(x)
310+
v
311+
+---+
312+
| A |
313+
+---+
314+
| calls B(A(x))
315+
v
316+
+---+
317+
| B |
318+
+---+
319+
| calls C(B(A(x)))
320+
v
321+
out
297322
```
298323

299324
## 7. Dynamics

0 commit comments

Comments
 (0)