design-patterns-typescript icon indicating copy to clipboard operation
design-patterns-typescript copied to clipboard

RealWorld examples

Open alfonsograziano opened this issue 3 years ago • 8 comments

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 :)

alfonsograziano avatar Jul 15 '22 14:07 alfonsograziano

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!

neochief avatar Jul 19 '22 16:07 neochief

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 :)

alfonsograziano avatar Jul 20 '22 06:07 alfonsograziano

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).

alfonsograziano avatar Jul 20 '22 06:07 alfonsograziano

Strategy => A simple file upload processor. You have different strategies (like LocalUpload, S3, GCloudStorage). The client code will upload the file using a context

alfonsograziano avatar Jul 20 '22 06:07 alfonsograziano

Decorator => Add telemetry to API call. The decorator decorates the controller and log the request info and response time

alfonsograziano avatar Jul 20 '22 06:07 alfonsograziano

Factory => Create different types of player based on the provided user token

alfonsograziano avatar Jul 20 '22 06:07 alfonsograziano

Looks great so far!

neochief avatar Jul 20 '22 21:07 neochief

Hi, Alfonso! This is just a follow-up, please let me know if you need anything.

neochief avatar Aug 02 '22 08:08 neochief