Skip to content

Commit e9352b3

Browse files
Merge pull request zoltantothcom#35 from zoltantothcom/dev
Expand patterns details
2 parents 23945e9 + 88b39e1 commit e9352b3

26 files changed

+126
-35
lines changed

__tests__/components/__snapshots__/Pattern.test.js.snap

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,19 @@ exports[`REFERENCE - Pattern component renders the individual pattern (Singleton
5959
<span
6060
className="c2"
6161
>
62-
Description:
62+
Definition:
6363
</span>
64-
This pattern restricts object creation for a class to only one instance.
64+
Ensure a class has only one instance and provide a global point of access to it.
65+
</p>
66+
<p>
67+
<span
68+
className="c2"
69+
>
70+
Use when…
71+
</span>
72+
73+
there must by only one instance of a class
74+
.
6575
</p>
6676
<h3>
6777
ES5

__tests__/pages/__snapshots__/Patterns.test.js.snap

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,19 @@ exports[`Patterns page renders the individual Pattern (Singleton) info 1`] = `
295295
<span
296296
className="c2"
297297
>
298-
Description:
298+
Definition:
299299
</span>
300-
This pattern restricts object creation for a class to only one instance.
300+
Ensure a class has only one instance and provide a global point of access to it.
301+
</p>
302+
<p>
303+
<span
304+
className="c2"
305+
>
306+
Use when…
307+
</span>
308+
309+
there must by only one instance of a class
310+
.
301311
</p>
302312
<h3>
303313
ES5

src/components/Pattern.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,15 @@ class Pattern extends React.Component {
7373
<Type>{pattern.type} pattern</Type>
7474
</p>
7575
<p>
76-
<SubHeader>Description:</SubHeader>
77-
{`This pattern ${pattern.hint}.`}
76+
<SubHeader>Definition:</SubHeader>
77+
{pattern.definition}
7878
</p>
79+
{pattern.when && (
80+
<p>
81+
<SubHeader>Use when&hellip;</SubHeader>
82+
&hellip;{pattern.when}.
83+
</p>
84+
)}
7985

8086
<h3>ES5</h3>
8187
<SyntaxHighlighter language="javascript" style={style}>

src/static/patterns/behavioral_chainOfResponsibility.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const CHAIN_OF_RESPONSIBILITY = {
22
id: 'chain_of_responsibility',
33
name: 'Chain of Responsibility',
44
type: 'behavioral',
5-
hint: 'delegates commands to a chain of processing objects',
5+
hint: 'A way of passing a request between a chain of objects',
6+
definition: `Avoid coupling the sender of a request to its receiver by giving more than one object a chance to
7+
handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.`,
8+
when: 'more than one object can handle a request and that information is known in runtime',
69
codeES5: `function ShoppingCart() {
710
this.products = [];
811

src/static/patterns/behavioral_command.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ const COMMAND = {
22
id: 'command',
33
name: 'Command',
44
type: 'behavioral',
5-
hint: 'creates objects which encapsulate actions and parameters',
5+
hint: 'Encapsulate a command request as an object',
6+
definition: `Encapsulate a request as an object, thereby letting you parameterize clients with different requests,
7+
queue or log requests, and support undoable operations.`,
8+
when:
9+
'you have a queue of requests to handle or you want to log them. Also when you want to have an «undo» action',
610
codeES5: `function Cockpit(instruction) {
711
this.instruction = instruction;
812
}

src/static/patterns/behavioral_interpreter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ const INTERPRETER = {
22
id: 'interpteter',
33
name: 'Interpreter',
44
type: 'behavioral',
5-
hint: 'implements a specialized language',
5+
hint: 'A way to include language elements in a program',
6+
definition: `Given a language, define a representation for its grammar along with an interpreter that
7+
uses the representation to interpret sentences in the language.`,
8+
when:
9+
'you want to interpret given language and you can represent statements as an abstract syntax trees',
610
codeES5: `function Sum(left, right) {
711
this.left = left;
812
this.right = right;

src/static/patterns/behavioral_iterator.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ const ITERATOR = {
22
id: 'iterator',
33
name: 'Iterator',
44
type: 'behavioral',
5-
hint:
6-
'accesses the elements of an object sequentially without exposing its underlying representation',
5+
hint: 'Sequentially access the elements of a collection',
6+
definition: `Provide a way to access the elements of an aggregate object sequentially
7+
without exposing its underlying representation.`,
8+
when: "you want to access object's content without knowing how it is internally represented",
79
codeES5: `function Pattern(el) {
810
this.index = 0;
911
this.elements = el;

src/static/patterns/behavioral_mediator.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ const MEDIATOR = {
22
id: 'mediator',
33
name: 'Mediator',
44
type: 'behavioral',
5-
hint:
6-
'allows loose coupling between classes by being the only class that has detailed knowledge of their methods',
5+
hint: 'Defines simplified communication between classes',
6+
definition: `Define an object that encapsulates how a set of objects interact.
7+
Mediator promotes loose coupling by keeping objects from referring to each other explicitly,
8+
and it lets you vary their interaction independently.`,
9+
when: 'a set of objects communicate in structured but complex ways',
710
codeES5: `function TrafficTower() {
811
this.airplanes = [];
912
}

src/static/patterns/behavioral_memento.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const MEMENTO = {
22
id: 'memento',
33
name: 'Memento',
44
type: 'behavioral',
5-
hint: 'provides the ability to restore an object to its previous state',
5+
hint: "Capture and restore an object's internal state",
6+
definition: `Without violating encapsulation, capture and externalize an object's internal state
7+
so that the object can be restored to this state later.`,
8+
when: 'you need to take a snapshot of an object',
69
codeES5: `function Pattern(value) {
710
this.value = value;
811
}

src/static/patterns/behavioral_observer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const OBSERVER = {
22
id: 'observer',
33
name: 'Observer',
44
type: 'behavioral',
5-
hint: 'is a publish/subscribe pattern which allows a number of observer objects to see an event',
5+
hint: 'A way of notifying change to a number of classes',
6+
definition: `Define a one-to-many dependency between objects so that when one object changes state,
7+
all its dependents are notified and updated automatically.`,
8+
when: 'a change to one object requires changing others',
69
codeES5: `function Product() {
710
this.price = 0;
811
this.actions = [];

0 commit comments

Comments
 (0)