Botcrafting / botcraft

Bot for Reading Club Telegram group chat
0 stars 0 forks source link

Chain of command #19

Closed thiagomuller closed 4 years ago

thiagomuller commented 4 years ago

Hey guys I'd like to request a pull request for another refactoring. I'm implementing chain of responsability design pattern in order to handle messages better and with a clearer code. Please note that this is a first version, we should refactor this implementation of the chain a bit to get it better. I would like to hear suggestions from you on how to improve this. If you will, we might merge this version in the meantime!

Btw, I also adapted Rodrigo's npe solution for the after the last great refactor, because npe reapeared!

Thanks!!

thiagomuller commented 4 years ago

After talking to Rodrigo, he gave me many ideas for refactoring this to a better version.

Now, instead of a chain class that creates a sequence of processors, we have a chain class that only have a list of processors and doesn't care about sequencing them. Each processor can register itself in the chain by calling chain.registerProcessor() method, this way, should we create new message handlers, all we have to do is implement a new processor and register it. The previous superclass became an interface, since we took off message and other attributes, since every processor and the chain itself should be stateless. We though that the attributes that were present in the superclass were Message specific attributes, so Message class received methods to handle this. I also refactored chain class to a better and more meaningfull name.

Feel free to give more suggestions if you will guys. If you don't have anything else to add, please review and merge the PR.

Thank you very much!!

thiagomuller commented 4 years ago

Rodrigo's suggestions were incorporated! Merging PR!