DEV Community

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

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.