Traits extended by one-line case classesBy Rodolphe Belouin,
Let's start talking about Scala, that pretty language making you able to use both object-oriented and functional programming paradigms.
If you've never heard about it, take a look at Scala School. You have to be at ease with trait and case class concepts to understand this post.
We all agree: keeping an abstract layer in your code is something good, but it's often painful when you have to rewrite n-times some children having a similar implementation.
I always try to keep that children readable and fast understandable by making them one-liners. Adding a child becomes quite easy, even for a non-scala developer.
Let's define a trait that will be the minimal representation of a message.No need for writing overriding methods. Actually, id and content parameters are defined as methods that implicitly override Message's methods. Nice, isn't it? ##Trait using serialization OK, that was quite simple. But how will you do if you have to create custom serializer object for each message type? In that example, we will be using the lift framework to (de)serialize JSON. If you don't know what are apply and unapply methods, just take a look at this sample code to understand their usage:
By clicking "Get started" I agree to Clever Cloud's Terms and Conditions