DEV Community

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

 
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.