GoF design patterns in Scala: Command v2, now with typeclasses

Manuel Rodríguez
Oct 5 · 1 min read

On the series about GoF patterns in Scala, last week I proposed an implementation of Command pattern. I wasn’t however fully satisfied with the result because of not being functional but Object Oriented, so this week I am proposing a different implementation. This one is fully functional, based on typeclasses.

Photo by Jp Valery on Unsplash

Before going to the implementation -which is pretty obvious- I’d like to point out a couple things.

  • Note that we are choosing the Receiver that will execute the instructions importing it as an instance. That is cool!
  • As a negative note, this implementation does not allow saving a list of commands and executing all of them like in the OO version. That is a serious limitation of this proposal, as one important characteristic of the Command pattern is being able to log the commands.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade