Skip to content

Commit 4dd1307

Browse files
committed
Update patterns details
1 parent ca135d8 commit 4dd1307

23 files changed

+89
-36
lines changed

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 = [];

src/static/patterns/behavioral_state.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const STATE = {
22
id: 'state',
33
name: 'State',
44
type: 'behavioral',
5-
hint: 'allows an object to alter its behavior when its internal state changes',
5+
hint: "Alter an object's behavior when its state changes",
6+
definition: `Allow an object to alter its behavior when its internal state changes.
7+
The object will appear to change its class.`,
8+
when: `the object's behaviour depends on its state and its behaviour changes in run-time depends on that state`,
69
codeES5: `function Order() {
710
this.pattern = new WaitingForPayment();
811

src/static/patterns/behavioral_strategy.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ const STRATEGY = {
22
id: 'strategy',
33
name: 'Strategy',
44
type: 'behavioral',
5-
hint: 'allows one of a family of algorithms to be selected on-the-fly at runtime',
5+
hint: 'Encapsulates an algorithm inside a class',
6+
definition: `Define a family of algorithms, encapsulate each one, and make them interchangeable.
7+
Strategy lets the algorithm vary independently from clients that use it.`,
8+
when: `you have many classes that differ in their behaviour.
9+
Strategies allow to configure a class with one of many behaviours`,
610
codeES5: `function ShoppingCart(discount) {
711
this.discount = discount;
812
this.amount = 0;

src/static/patterns/behavioral_template.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ const TEMPLATE = {
22
id: 'template',
33
name: 'Template',
44
type: 'behavioral',
5-
hint:
6-
'defines the skeleton of an algorithm as an abstract class, allowing its subclasses to provide concrete behavior',
5+
hint: 'Defer the exact steps of an algorithm to a subclass',
6+
definition: `Define the skeleton of an algorithm in an operation, deferring some steps to subclasses.
7+
Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.`,
8+
when: `you have to define steps of the algorithm once and let subclasses to implement its behaviour`,
79
codeES5: `function Tax() {}
810
911
Tax.prototype.calc = function(value) {

0 commit comments

Comments
 (0)