design-patterns-typescript
design-patterns-typescript copied to clipboard
RealWorld examples
Hello, I would like to work on RealWorld examples for this repository (this is my first contribution to a project). Before to start I would really appreciate an ok from the maintainers and, if needed, advices. I will create the PR with examples in the next days :)
Hi!
Sure, you're more than welcome! However, before you write any code, I would appreciate it if you could send a simple outline for each pattern and describe in a few words what would be the scenario for the example. I'd like to avoid the standard "imagine that you have a pizza and pizza toppings" examples and instead have the actual Real World TypeScript stuff. Thanks a lot!
Great idea!
I think it is better to work in "chunks" so I'll explain my idea for some patterns and I will wait for you review in order to write the working code :)
Facade => The facade class expose a method "processUserData" (for Analytics) and uses 3 objects (Extractor, Transformer, Loader). The extractor get the data (from disk, remote api call, db etc), the transformer execute operations on the data and the Loader load the data. In my real example I will read a .log file with user signup and create in output a CSV file with the number of users registered per day (for example: 23/05/2022, 12).
Strategy => A simple file upload processor. You have different strategies (like LocalUpload, S3, GCloudStorage). The client code will upload the file using a context
Decorator => Add telemetry to API call. The decorator decorates the controller and log the request info and response time
Factory => Create different types of player based on the provided user token
Looks great so far!
Hi, Alfonso! This is just a follow-up, please let me know if you need anything.