Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions patterns/01-design-patterns-gof/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Origin. Gamma, Helm, Johnson, Vlissides 1994

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

## Behavioral
Expand All @@ -15,7 +15,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
| [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. |
| [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. |
| [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. |
| [Observer](observer.md) | canonical | 13,321 | A piece of state changes, and an unknown number of other pieces of the system need to react. |
| [Observer](observer.md) | canonical | 13,315 | A piece of state changes, and an unknown number of other pieces of the system need to react. |
| [Servant](servant.md) | contested | 5,677 | Wikipedia's own definition, quoted directly. |
| [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. |
| [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. |
Expand Down
59 changes: 37 additions & 22 deletions patterns/01-design-patterns-gof/observer.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,28 +286,43 @@ leak possible, and the two facts are the same fact.
## 6. ASCII structure diagram

```
+--------------------------------+ +----------------------+
| Subject | holds | Observer |
|--------------------------------| 0..* |----------------------|
| - observers: List<Observer> |--------->| + update(subject?) |
| + attach(o): Registration | +----------------------+
| + detach(reg) | ^ ^
| # notify() | | |
+--------------------------------+ | |
^ | |
| extends implements | | implements
| | |
+--------------------------------+ +--------------------+---------+
| ConcreteSubject | reads | ConcreteObserverA | ...B |
|--------------------------------|<- - - - -|--------------------|----------|
| - state: State | (pull) | - subject: ref | - cache |
| + getState(): State | | + update(...) | + update |
| + setState(s) -> notify() | +--------------------+----------+
+--------------------------------+

Solid arrow = compile time dependency.
Dashed arrow = the pull model back reference. Absent in the push model.
The Registration returned by attach() is the only thing that can detach.
+-----------------------------+
| Subject |
| - observers: List<Observer> |
| + attach(o): Registration |
| + detach(reg) |
| # notify() |
+-----------------------------+
| holds 0..*
v
+--------------------+
| Observer |
| + update(subject?) |
+--------------------+

+----------------------------------+
| ConcreteSubject, extends Subject |
| - state: State |
| + getState(): State |
| + setState(s) -> notify() |
+----------------------------------+
| reads (pull), dashed back reference
v
+----------------------------------------+
| ConcreteObserverA, implements Observer |
| - subject: ref |
| + update(...) |
+----------------------------------------+
+----------------------------------------+
| ConcreteObserverB, implements Observer |
| - cache |
| + update |
+----------------------------------------+

Solid arrow means a compile-time dependency. Dashed
arrow is the pull model's back reference, absent in the
push model. The Registration returned by attach() is
the only thing that can detach.
```

## 7. Dynamics
Expand Down
6 changes: 3 additions & 3 deletions patterns/02-code-smells/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Origin. Fowler and Beck, Refactoring

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

## Bloaters
Expand All @@ -11,7 +11,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
|---|---|---|---|
| [Data Clumps](data-clumps.md) | canonical | 5,832 | The smell shows up first in method signatures. |
| [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. |
| [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. |
| [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. |
| [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. |
| [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. |

Expand All @@ -28,7 +28,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
| Pattern | Maturity | Words | Intent |
|---|---|---|---|
| [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. |
| [Dead Code](dead-code.md) | canonical | 9,473 | Dead code accumulates as an ordinary, unavoidable byproduct of change. |
| [Dead Code](dead-code.md) | canonical | 9,466 | Dead code accumulates as an ordinary, unavoidable byproduct of change. |
| [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 ... |
| [Loops](loops.md) | canonical | 8,826 | A loop is the most flexible construct available in an imperative language. |
| [Middle Man](middle-man.md) | canonical | 7,237 | The smell shows up during evolution, almost never at the moment a class is first written. |
Expand Down
75 changes: 40 additions & 35 deletions patterns/02-code-smells/dead-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,41 +270,46 @@ indistinguishable, to the next reader, from a claim that happens to be wrong.
## 6. ASCII structure diagram

```
REACHABILITY GRAPH
===================

entry points live subgraph dead subgraph
------------- -------------- -------------

main() ----+ +--> handleOrder() applyLegacyDiscount()
| | | (no incoming edge
httpRoute +---> dispatch() -+--> applyTax() from any entry
/orders | | point below)
| +--> validate()
cronJob |
nightly +---> reconcile()-+--> readLedger() [dead subgraph has
| zero paths back
+--> writeLedger() to any entry point]


GUARD-GATED BRANCH
===================

process(order)
|
v
+---------------------------+
| if legacyFlag.isEnabled() | <-- legacyFlag hardcoded false
| doLegacyPath(order) | in every environment since
| else | the rollout finished
| doCurrentPath(order) |
+---------------------------+
| |
v v
doLegacyPath doCurrentPath <-- structurally reachable,
(dead: guard (live: the practically dead, needs the
never true) only path guard's known value as evidence,
taken) not the call graph alone
REACHABILITY GRAPH

Entry points: main(), httpRoute /orders, cronJob nightly

main() and httpRoute /orders both call dispatch(), which
calls:
handleOrder()
applyTax()
validate()

cronJob nightly calls reconcile(), which calls:
readLedger()
writeLedger()

This is the live subgraph, every function above has a path
back to an entry point.

Dead subgraph: applyLegacyDiscount(). No incoming edge from
any entry point above, zero paths back to any entry point.


GUARD-GATED BRANCH

process(order)
|
v
if legacyFlag.isEnabled():
doLegacyPath(order)
else:
doCurrentPath(order)

legacyFlag is hardcoded false in every environment since the
rollout finished.

doLegacyPath: dead, guard never true.
doCurrentPath: live, the only path actually taken.

doLegacyPath is structurally reachable but practically dead,
needs the guard's known value as evidence, not the call
graph alone.
```

## 7. Dynamics
Expand Down
85 changes: 45 additions & 40 deletions patterns/02-code-smells/large-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,46 +275,51 @@ to update in the same commit that performs the split.
## 6. ASCII structure diagram

```
Before, one class, several unrelated responsibility clusters:

+--------------------------------------------------+
| Order |
|----------------------------------------------------|
| - lineItems, customerId, discountCode | cluster A: pricing
| - taxRate, currency |
| - shippingAddress, billingAddress | cluster B: fulfillment
| - trackingNumber, carrier |
| - emailTemplate, smtpConfig | cluster C: notification
| - auditLog | cluster D: audit
|----------------------------------------------------|
| + calculateSubtotal() | cluster A methods
| + applyDiscount() |
| + calculateTax() |
| + scheduleShipment() | cluster B methods
| + assignCarrier() |
| + sendConfirmationEmail() | cluster C methods
| + sendShippingNotice() |
| + recordAuditEntry() | cluster D methods
+--------------------------------------------------+

After, Extract Class applied per cluster, Original Class delegates:

+--------------+ uses +-------------------+
| Order | ------------> | OrderPricer |
| (core state) | | (cluster A logic) |
+--------------+ +-------------------+
| uses +-------------------------+
+--------------> | ShipmentScheduler |
| | (cluster B logic) |
| +-------------------------+
| uses +-------------------------+
+--------------> | OrderNotifier |
| | (cluster C logic) |
| +-------------------------+
| uses +-------------------------+
+--------------> | OrderAuditLog |
| (cluster D logic) |
+-------------------------+
Before, one class, several unrelated responsibility
clusters:

+---------------------------------------------+
| Order |
| cluster A, pricing: lineItems, customerId, |
| discountCode, taxRate, currency |
| cluster B, fulfillment: shippingAddress, |
| billingAddress, trackingNumber, carrier |
| cluster C, notification: emailTemplate, |
| smtpConfig |
| cluster D, audit: auditLog |
| |
| cluster A methods: calculateSubtotal(), |
| applyDiscount(), calculateTax() |
| cluster B methods: scheduleShipment(), |
| assignCarrier() |
| cluster C methods: sendConfirmationEmail(), |
| sendShippingNotice() |
| cluster D methods: recordAuditEntry() |
+---------------------------------------------+

After, Extract Class applied per cluster, Original
Class delegates:

+--------------------+
| Order (core state) |
+--------------------+
| uses
v
+-------------------------------+
| OrderPricer (cluster A logic) |
+-------------------------------+
+-------------------------------------+
| ShipmentScheduler (cluster B logic) |
+-------------------------------------+
+---------------------------------+
| OrderNotifier (cluster C logic) |
+---------------------------------+
+---------------------------------+
| OrderAuditLog (cluster D logic) |
+---------------------------------+

Order uses all four, each handling one cluster's
logic.
```

## 7. Dynamics
Expand Down
4 changes: 2 additions & 2 deletions patterns/05-architectural/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Origin. Buschmann POSA 1, Bass SEI

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

## Architectural
Expand Down Expand Up @@ -30,7 +30,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
| [Multi-Tenant Architecture](multi-tenant-architecture.md) | canonical | 5,015 | A SaaS provider serves many customers, called tenants, from one running application. |
| [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 ... |
| [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. |
| [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 ... |
| [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 ... |
| [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 ... |
| [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 ... |
| [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 ... |
Expand Down
71 changes: 48 additions & 23 deletions patterns/05-architectural/pipeline-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,29 +271,54 @@ survives in a variable called pipeline.
## 6. ASCII structure diagram

```
DATA SOURCE DATA SINK
(file, socket, (file, socket,
queue, request) queue, response)
| ^
v |
+-----------+ pipe +-----------+ pipe +-----------+
| FILTER A |------------->| FILTER B |------------->| FILTER C |
| (e.g. | [buffer, | (e.g. | [buffer, | (e.g. |
| parse) | backpress] | enrich) | backpress] | encode) |
+-----------+ +-----------+ +-----------+
^ ^ ^
| | |
single input, single input, single input,
single output single output single output
(uniform contract (uniform contract (uniform contract
shared by every shared by every shared by every
filter in the chain) filter in the chain) filter in the chain)

Optional PUMP drives passive filters that have no thread of their own.

+------+ calls A(x) +---+ calls B(A(x)) +---+ calls C(B(A(x)))
| PUMP |--------------->| A |------------------->| B |------------------> out
+------+ +---+ +---+
+--------------------------------------------+
| Data Source (file, socket, queue, request) |
+--------------------------------------------+
| single input/output uniform contract
v
+----------------------------+
| Filter A, e.g. parse |
| pipe, buffer, backpressure |
+----------------------------+
|
v
+----------------------------+
| Filter B, e.g. enrich |
| pipe, buffer, backpressure |
+----------------------------+
|
v
+-----------------------+
| Filter C, e.g. encode |
+-----------------------+
|
v
+-------------------------------------------+
| Data Sink (file, socket, queue, response) |
+-------------------------------------------+

Every filter shares the same uniform contract, single
input, single output.

Optional PUMP drives passive filters that have no
thread of their own:

+------+
| PUMP |
+------+
| calls A(x)
v
+---+
| A |
+---+
| calls B(A(x))
v
+---+
| B |
+---+
| calls C(B(A(x)))
v
out
```

## 7. Dynamics
Expand Down
4 changes: 2 additions & 2 deletions patterns/12-data-storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Origin. Kleppmann

45 entries, 319,823 words. Every entry carries all 18
45 entries, 319,776 words. Every entry carries all 18
dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).

## Concurrency Control
Expand Down Expand Up @@ -49,7 +49,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
| [Lamport Clock](lamport-clock.md) | canonical | 6,460 | A distributed system has no shared memory and no shared clock. |
| [Leaderless Replication](leaderless-replication.md) | canonical | 7,925 | A single-leader replicated database routes every write through one node. |
| [Log Compaction](log-compaction.md) | established | 8,019 | An append-only log is the simplest and most dependable storage primitive a distributed system offers. |
| [Medallion Architecture](medallion-architecture.md) | established | 7,094 | A data platform ingests information from many upstream systems. |
| [Medallion Architecture](medallion-architecture.md) | established | 7,047 | A data platform ingests information from many upstream systems. |
| [Multi-Leader Replication](multi-leader-replication.md) | established | 7,911 | A team runs a database that serves write traffic from more than one geographic region, or from more than one autonomous system that must keep working during a network partition ... |
| [Multiversion Concurrency Control](mvcc.md) | canonical | 7,230 | A database serves many concurrent transactions. |
| [Quorum](quorum.md) | canonical | 7,448 | A system replicates the same piece of data onto several nodes so that the loss of any one node, or the temporary unavailability of any one node, does not lose data or stop the ... |
Expand Down
Loading
Loading