Skip to content

Commit 98bb0dc

Browse files
committed
updated README
1 parent 0e7336f commit 98bb0dc

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

srp/README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Another way of putting this would be to say each class should do one thing and d
1212

1313
## Reasons for Change
1414

15-
What is the reason for the [FileStore class](./src/before/fileStore.ts) to change (Answer is below!):
15+
What is the reason for the [FileStore class](./src/before/FileStore.ts) to change (Answer is below!):
1616

1717
The answers are:
1818

@@ -25,11 +25,30 @@ The answers are:
2525

2626
What we do is take each one of the reasons for change listed above and extract into a separate class.
2727

28-
So firstly, let's extract all _logging logic_ into a new class called [StoreLogger](./src/after/storeLogger.ts) like so. Note that it is domain specific for our Store and not just a generic Logger.
28+
So firstly, let's extract all _logging logic_ into a new class called [StoreLogger](./src/after/StoreLogger.ts) like so. Note that it is domain specific for our Store and not just a generic Logger.
2929

3030
What we have done is extracted all the various log calls to a new class. Now this means that if we want to change the logging framework that we use - perhaps because the open source project that built the logger framework becomes depreciated or we find a better solution well now we can change in just this one place.
3131

32-
To use this new logger, we create an instance of it in the [message store class](./src/after/messageStore.ts) - perviously called FileStore (I'll explain why the name was changed below).
32+
To use this new logger, we create an instance of it in the [message store class](./src/after/MessageStore.ts) - perviously called FileStore (I'll explain why the name was changed below).
33+
34+
Now we replace the calls to `console.xyz(...)` to `this.log.xyz(...)` for example:
35+
36+
* Replace: `console.log(“some message: ”, id)`
37+
* With: `this.log.Saving(id)`
38+
39+
The next thing we need to extract is the logic for caching which can be applied in pretty much the same way. We create a new class [StoreCache](./src/after/StoreCache.ts).
40+
41+
Then we need to create an instance of this class in our MessageStore class and call that instead through the implementation.
42+
43+
```
44+
this.cache = new StoreCache(); // in the MessageStore constructor
45+
---
46+
this.cache.AddOrUpdate(id, message); // in the Save method
47+
```
48+
49+
Next reason to change that we can address is the way that we apply storage. This will allow us to change where we save files - perhaps to a relational database instead of a filestore- who knows! So what we do is create a separate class called FileSore that is just for reading / writing files to the filestore and use that in our MessageStore class in the same way as before.
50+
51+
So what are we left with? A better implementation for this class that is now split into other classes each with a Single Responsibility!
3352

3453
## Running the application
3554

0 commit comments

Comments
 (0)