-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
153 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- | ||
High Cohesion is a software design principle that emphasizes organizing and structuring code in a way that closely related functions and data are grouped together within a module or class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- | ||
A class that has all the required information to perform a task (make a decision) should be assigned to do it. In general, this means that all the internal logic of a functionality should be controlled by the 'nearest' class to which its functionality belongs. | ||
# Example | ||
```js | ||
class Product { | ||
constructor(name, productPrice) { | ||
this.name = name; | ||
this.productPrice = productPrice; | ||
} | ||
// this class knows everything about products. Therefore this class is an information expert to calculate its price. | ||
get price() { | ||
return this.productPrice; | ||
} | ||
} | ||
|
||
class Purchase { | ||
constructor(name, ...collection) { | ||
this.name = name; | ||
this.collection = collection; | ||
} | ||
// this class knows everything about purchases. Therefore this class is an information expert to calculate its price. | ||
get price() { | ||
return this.collection.reduce((sum, entity) => { | ||
// class Purchase doesn't need to know how to calculate price of each individual entity. It's up to these entities. He only knows that price of any entity is available by a public field price. These entities in their turn are information experts to calculate their price | ||
return sum += entity.price; | ||
}, 0); | ||
} | ||
} | ||
|
||
const product1 = new Product('Laptop', 2000); | ||
const product2 = new Product('Mouse', 40); | ||
const purchase1 = new Purchase('Work kit', product1, product2); | ||
|
||
const product3 = new Product('Book', 100); | ||
const product4 = new Product('iPhone', 1000); | ||
|
||
const total = new Purchase('All together', purchase1, product3, product4); | ||
|
||
// Now it's easy to calculate total price | ||
console.log(total.price); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- | ||
modules/classes/functions should know about the properties of other modules/classes/functions only as much as they need to. The less they know, the more readable your code becomes, and it becomes easier to extend and modify. This principle also relates to defining architecture boundaries. | ||
|
||
The middleware concept is a good example of a violation of this principle. Each middleware can modify the HTTP `request`/`response`. Often, middlewares should be executed in a specific order because one middleware can add a new field to the `request` object while another one relies on the existence of this field. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- | ||
Pure fabrication refers to entities that do not exist in the business domain but are abstractions within the program. These abstractions can be system-level constructs that are easy to reuse. Such abstractions help reduce the amount of system-specific code within the business domain. | ||
## Examples | ||
Promise, Socket, Connection, Proxy, Request, Response, Server, Stream, Queue, Transaction, etc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
tags: | ||
- architecture | ||
- grasp | ||
--- | ||
GRASP - General responsibility assignment software patterns | ||
|
||
> [!INFO] | ||
> First was proposed by Craig Larman in his book "Applying UML and Patterns" | ||
## Principles | ||
- [[arch-grasp-low-coupling|Low Coupling]] | ||
- [[arch-grasp-information-expert|Information Expert]] | ||
- [[arch-grasp-controller|Controller]] | ||
- [[arch-grasp-pure-fabrication|Pure Fabrication]] | ||
- [[arch-grasp-protected-variations|Protected Variations]] | ||
- [[arch-grasp-high-cohesion|High Cohesion]] | ||
- [[arch-grasp-creator|Creator]] | ||
- [[arch-grasp-polymorphism|Polymorphism]] | ||
- [[arch-grasp-indirection|Indirection]] | ||
|
||
### Creator | ||
Problem: Who should create instance(who should hold and destroy link) | ||
|
||
Solution: Who contains or aggregate instances, who use them heavily, who has all the information for initialization. | ||
|
||
Why: to low coupling | ||
|
||
Examples: constructor, factory, pool |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters