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

Manuel Rodríguez
1 min readOct 5, 2019

--

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.

--

--

Manuel Rodríguez

Developer at New Relic. This is where I keep the cool stuff that I learn in my free time