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
54 changes: 34 additions & 20 deletions patterns/03-refactoring/encapsulate-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,40 @@ class enforces its invariants in those methods.
## 6. ASCII structure diagram

```
BEFORE AFTER
------ -----

class Course: class Course:
attendees: List<Student> _attendees: List<Student> (private)
MAX = 30
getAttendees(): List<Student>
return attendees getAttendees(): List<Student>
return unmodifiable(_attendees)
caller:
course.getAttendees().add(s) enroll(student):
// bypasses capacity check if len(_attendees) >= MAX:
raise FullError
_attendees.add(student)

cancel(student):
_attendees.remove(student)

caller:
course.enroll(s) // checked
BEFORE
------

class Course:
attendees: List<Student>

getAttendees(): List<Student>
return attendees

caller:
course.getAttendees().add(s)
// bypasses capacity check


AFTER
-----

class Course:
_attendees: List<Student> (private)
MAX = 30

getAttendees(): List<Student>
return unmodifiable(_attendees)

enroll(student):
if len(_attendees) >= MAX:
raise FullError
_attendees.add(student)

cancel(student):
_attendees.remove(student)

caller:
course.enroll(s) // checked
```

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

Origin. Martin, Larman, Brewer, Conway

42 entries, 327,228 words. Every entry carries all 18
42 entries, 327,232 words. Every entry carries all 18
dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).

## Design Principle
Expand Down Expand Up @@ -35,7 +35,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
| [Controller](controller.md) | canonical | 6,874 | A team wiring a new interaction into an object-oriented system reaches a concrete, recurring question the moment a user clicks a button, submits a form, or an external system ... |
| [Conway's Law](conway-law.md) | canonical | 7,751 | A team is asked to build a system with several distinct concerns. |
| [Creator](creator.md) | canonical | 7,514 | Every object-oriented system eventually needs a new object of type A to come into existence somewhere, and the code that calls the constructor has to live in some class B. |
| [Do Not Repeat Yourself](do-not-repeat-yourself.md) | canonical | 6,449 | A single fact about the system, a tax rate, a validation rule, a URL, a unit conversion, a business rule about who is allowed to approve a refund, gets written down in more than ... |
| [Do Not Repeat Yourself](do-not-repeat-yourself.md) | canonical | 6,453 | A single fact about the system, a tax rate, a validation rule, a URL, a unit conversion, a business rule about who is allowed to approve a refund, gets written down in more than ... |
| [Fail Fast](fail-fast.md) | established | 7,090 | A running program encounters a state it was not written to handle correctly. |
| [High Cohesion](high-cohesion.md) | canonical | 8,014 | A team splits a system into modules, classes, packages, or services, and almost every split is defensible on some axis. |
| [Idiomatic](idiomatic.md) | canonical | 7,073 | A person who learns to program in one language carries that language's mental model into every language learned afterward. |
Expand Down
50 changes: 34 additions & 16 deletions patterns/04-principles-and-laws/do-not-repeat-yourself.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,40 @@ mechanism carries it out.
## 6. ASCII structure diagram

```
Before After

+----------------+ +----------------+
| Checkout code | | Checkout code |
| tax = p * r | | orderTotal(p,r)|--+
+----------------+ +----------------+ |
v
+----------------+ +----------------+ +-----------------+
| Receipt code | | Receipt code | | orderTotal(p,r) |
| tax = p * r | | orderTotal(p,r)|->| single, owned, |
+----------------+ +----------------+ | authoritative |
+-----------------+
Two independent copies of the One representation, two consumers
formula. A tax-law change means bound to it. A tax-law change means
finding and editing both, and editing one function. Both callers
nothing enforces they still match. agree by construction, not by care.
Before

+---------------+
| Checkout code |
| tax = p * r |
+---------------+
+--------------+
| Receipt code |
| tax = p * r |
+--------------+

Two independent copies of the formula. A tax-law
change means finding and editing both, and nothing
enforces they still match.

After

+------------------+
| Checkout code |
| orderTotal(p, r) |
+------------------+
+------------------+
| Receipt code |
| orderTotal(p, r) |
+------------------+
| both call
v
+------------------------------------------------+
| orderTotal(p, r), single, owned, authoritative |
+------------------------------------------------+

One representation, two consumers bound to it. A
tax-law change means editing one function. Both
callers agree by construction, not by care.
```

## 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,937 words. Every entry carries all 18
31 entries, 248,910 words. Every entry carries all 18
dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).

## Architectural
Expand Down Expand Up @@ -36,7 +36,7 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
| [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 ... |
| [Primary-Replica](primary-replica.md) | canonical | 7,665 | A single database instance handling both writes and reads eventually hits a ceiling on at least one of three axes, read throughput, availability, and geographic latency. |
| [Serverless Architecture](serverless-architecture.md) | established | 8,872 | A team owns a backend that must handle a workload with two properties that are hard to satisfy at once with a conventional server fleet, the load is spiky or unpredictable, and ... |
| [Service-Oriented Architecture](service-oriented-architecture.md) | contested | 6,727 | A monolithic application starts as the fastest way to ship. |
| [Service-Oriented Architecture](service-oriented-architecture.md) | contested | 6,700 | A monolithic application starts as the fastest way to ship. |
| [Shared Nothing](shared-nothing.md) | canonical | 7,785 | A system needs to handle more work than one machine can handle, whether that work is transaction throughput, storage volume, or concurrent connections. |
| [Space-Based Architecture](space-based-architecture.md) | established | 7,002 | A system built as a stateless application tier in front of a single relational database scales the application tier easily and the database tier badly. |
| [VIPER](viper.md) | established | 8,403 | A screen in a UIKit or AppKit application tends to accumulate three kinds of code inside one view controller, code that lays out and updates the user interface, code that decides ... |
Expand Down
59 changes: 33 additions & 26 deletions patterns/05-architectural/service-oriented-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,32 +262,39 @@ the rule.
## 6. ASCII structure diagram

```
+----------------------+
| Service Registry |
| (contracts, versions, |
| network locations) |
+-----------+------------+
^
register / | discover
publish | |
v v
+----------------+ +--------------------+ +------------------+
| Service |----->| API Gateway / |<-----| Service |
| Consumer | | Enterprise | | Consumer |
| (client app, | | Service Bus | | (another service) |
| batch job) |<-----| (routing, auth, |----->| |
+----------------+ | policy, optional) | +------------------+
+----------+---------+
|
+-------------------+-------------------+
| | |
v v v
+--------------------+ +--------------------+ +--------------------+
| Service Provider A | | Service Provider B | | Service Provider C |
| (e.g. Orders) | | (e.g. Inventory) | | (e.g. Payments) |
| Contract. OrderAPI | | Contract. StockAPI | | Contract. PayAPI |
| Owns. orders DB | | Owns. stock DB | | Owns. ledger DB |
+--------------------+ +--------------------+ +--------------------+
+----------------------------------------+
| Service Registry |
| contracts, versions, network locations |
+----------------------------------------+
^ register / publish, discover
|
+--------------------------------------+
| API Gateway / Enterprise Service Bus |
| routing, auth, policy, optional |
+--------------------------------------+
^ used by
|
+-------------------------------------------+
| Service Consumer, client app or batch job |
+-------------------------------------------+
+-----------------------------------+
| Service Consumer, another service |
+-----------------------------------+

API Gateway / ESB routes to three providers:

+-----------------------------------+
| Service Provider A, e.g. Orders |
| Contract OrderAPI, owns orders DB |
+-----------------------------------+
+------------------------------------+
| Service Provider B, e.g. Inventory |
| Contract StockAPI, owns stock DB |
+------------------------------------+
+-----------------------------------+
| Service Provider C, e.g. Payments |
| Contract PayAPI, owns ledger DB |
+-----------------------------------+
```

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

Origin. Fowler, PoEAA

56 entries, 371,808 words, 4 more planned, 60 total when the family is complete. Every entry carries all 18
56 entries, 371,715 words, 4 more planned, 60 total when the family is complete. Every entry carries all 18
dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).

## Base Pattern
Expand Down Expand Up @@ -122,13 +122,13 @@ dimensions from [the entry contract](../../docs/ENTRY-TEMPLATE.md).
| Pattern | Maturity | Words | Intent |
|---|---|---|---|
| [Embedded Value](embedded-value.md) | canonical | 7,871 | An application's domain model routinely needs small objects that group a handful of related fields into one meaningful unit. |
| [Identity Field](identity-field.md) | canonical | 6,033 | An in-memory object system and a relational database use two different, and incompatible, notions of identity. |
| [Identity Field](identity-field.md) | canonical | 6,034 | An in-memory object system and a relational database use two different, and incompatible, notions of identity. |

## Object-Relational Structural Patterns

| Pattern | Maturity | Words | Intent |
|---|---|---|---|
| [Concrete Table Inheritance](concrete-table-inheritance.md) | canonical | 8,078 | An application's domain model contains a base type with several concrete subtypes, each subtype adding its own fields, and the persistence layer must map that hierarchy onto ... |
| [Concrete Table Inheritance](concrete-table-inheritance.md) | canonical | 7,984 | An application's domain model contains a base type with several concrete subtypes, each subtype adding its own fields, and the persistence layer must map that hierarchy onto ... |
| [Inheritance Mappers](inheritance-mappers.md) | canonical | 8,397 | A domain model with an inheritance hierarchy, a base Employee class with SalariedEmployee, CommissionedEmployee, and HourlyEmployee subclasses, needs a persistence layer that can ... |
| [Single Table Inheritance](single-table-inheritance.md) | canonical | 9,071 | An object model has a natural inheritance hierarchy. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,52 +280,57 @@ matters more than the rule.
## 6. ASCII structure diagram

```
+---------------------------+
| PaymentMethod |
| in-memory only, |
| no table |
|-----------------------------|
| + amount |
| + currency |
| + createdAt |
+---------------------------+
^ ^ ^
| | |
+---------------+ +------+-----+ +-+----------------+
| CreditCardPayment| | BankTransfer| | PayPalPayment |
|------------------| | Payment | |------------------|
| + maskedPan | |-------------| | + payerEmail |
| + expiryMonth | | + iban | | + payerId |
+---------+--------+ | + bic | +---------+--------+
| +------+------+ |
| | |
v v v
+-------------------+ +-------------------+ +-------------------+
| credit_card_ | | bank_transfer_ | | paypal_ |
| payments TABLE | | payments TABLE | | payments TABLE |
|--------------------| |---------------------| |--------------------|
| id, PK, seq | | id, PK, seq | | id, PK, seq |
| amount | | amount | | amount |
| currency | | currency | | currency |
| created_at | | created_at | | created_at |
| masked_pan | | iban | | payer_email |
| expiry_month | | bic | | payer_id |
+--------------------+ +----------------------+ +--------------------+

No table exists for PaymentMethod. No foreign key connects the three
concrete tables to one another. The shared columns amount, currency,
and created_at are physically duplicated in every table.

A rare polymorphic read is served by a UNION ALL, roughly like this.

SELECT id, amount, currency, created_at, 'card' AS kind
FROM credit_card_payments
UNION ALL
SELECT id, amount, currency, created_at, 'transfer' AS kind
FROM bank_transfer_payments
UNION ALL
SELECT id, amount, currency, created_at, 'paypal' AS kind
FROM paypal_payments
+-----------------------------------------+
| PaymentMethod, in-memory only, no table |
| + amount |
| + currency |
| + createdAt |
+-----------------------------------------+
^ extended by three subclasses
|
+-------------------+
| CreditCardPayment |
| + maskedPan |
| + expiryMonth |
+-------------------+
|
v
+------------------------------------------+
| credit_card_payments TABLE |
| id PK seq, amount, currency, created_at, |
| masked_pan, expiry_month |
+------------------------------------------+

+---------------------+
| BankTransferPayment |
| + iban |
| + bic |
+---------------------+
|
v
+------------------------------------------------+
| bank_transfer_payments TABLE |
| id PK seq, amount, currency, created_at, iban, |
| bic |
+------------------------------------------------+

+---------------+
| PayPalPayment |
| + payerEmail |
| + payerId |
+---------------+
|
v
+------------------------------------------+
| paypal_payments TABLE |
| id PK seq, amount, currency, created_at, |
| payer_email, payer_id |
+------------------------------------------+

No table exists for PaymentMethod. No foreign key
connects the three concrete tables to one another. The
shared columns amount, currency, and created_at are
physically duplicated in every table.
```

## 7. Dynamics
Expand Down
Loading
Loading