DEV Community

Discussion on: Design patterns. How do you select yours?

Collapse
 
imthedeveloper profile image
ImTheDeveloper • Edited

I've actually been looking at doing this. Not just for design patterns but for JavaScript in general. I read a lot and there's only so much information I can take in. I often know there is a concept out there or need a slight prompt. I believe cheat sheets are a great way to jog your memory. I found them especially useful back when I was learning new languages.

I think in this case there is a distinction between the patterns used within modules and then there's the patterns used to organise my projects & modules. In the cheat sheet it terms these are structural vs creational which is a great initial distinction to make!

Your post has actually got me on the hunt for some other cheat sheets github.com/addyosmani/essential-js...

Collapse
 
bgadrian profile image
Adrian B.G.

Yes there are many patterns and you only use them when starting a new project / system / module, impossible to remember them all.

Especially in JS where you can jog between multiple programming paradigms, our brain can be overloaded so cheatsheets are here to rescue us. From DRY/SOLID principles to JS module patterns it's good to make some wall posters from them.

Thread Thread
 
imthedeveloper profile image
ImTheDeveloper

Good point around the beginning of the project. I'm just starting out building a telegram bot which will use a lot of custom commands for authenticated users.

I've decided instead of doing my usual "write code - suffer pain - refactor" mantra I will plan out elements of the architecture.

As an example, since every message would be running through my application I expect a middleware pattern would be useful for logging, checking for authentication levels, spotting messages that contain commands and attaching a custom handler.

Once the message is picked up by the handler I could use a plugin based architecture as there are many commands that I would treat as custom hooks to be fired in response to the routed command.

Even having a rough implementation view at this level will help to structure my project. I can then begin delving into the creation patterns such as an InstantMessage class which creates a structure I can then utilise in my concrete classes which hold the detail of the commands.

Thread Thread
 
bgadrian profile image
Adrian B.G.

Offtopic - I made some bots in the last 2 years and I came across this generator that does something simple and beautiful

  • each command is a file (module)
  • each command receive the message & client, returns a message or error
  • each command describe itself
Thread Thread
 
imthedeveloper profile image
ImTheDeveloper

Thanks for this sounds like it will give me a nice framework to review and steal with pride.