Traits

Back2Basics: The Story of Trait – Part 4

In our previous blog The Story of Trait – Part 3, we have discussed the mixin, one of the charming feature of traits. Now we are going to explore chaining of traits. We have seen how can we mix more than one traits into classes. But what would happen if two traits have same method i.e same name and same signature? This is where Multiple Inheritance Continue Reading

Back2Basics: Catalogue #1

Knoldus Inc is proud to announce the launch of program “Back2Basics”. Back2Basics is our effort to add value to the Scala ecosystem by exploring not so explored concepts in Scala. The idea behind the inception of the program is to develop an understanding of Scala concepts that are hard to understand and not frequently used by developers. In this program, we have two parallel tracks Continue Reading

Back2Basics: The Story of Trait – Part 3

In our previous blog The Story of Trait – Part 2, we have discussed that traits can have implementation too and how they behave under the hood. In this blog, we will discuss mixins one of the most charming features of traits. Mixins are the wonderful concept of object-oriented programming. Sadly, some of the mainstream object-oriented programming languages like C++, Java, C#, have not provided Continue Reading

Back2Basics: The Story of Trait – Part 2

In our previous blog The Story of Trait – Part 1, we have discussed how traits are the just regular interfaces at the very basic form. In this blog, we will explore about traits can have method implementation too. We will continue with our previous example and modify it and see how trait behaves in different scenarios.

Back2Basics: The Story of Trait – Part 1

In this blog, we will have a look at traits in Scala. We have classes in Scala. Suppose we have a class Dog which has a method speak. class Dog(val name: String){ def speak() = println(s”$name is barking”) } Now if we want another class Cat which has the same method speak. What we will do? In Java, generally, we create an interface Animal and Continue Reading

Scala Trait and Mixin – Points to Remember

Scala Trait and Mixin – Points to Remember Trait can be viewed not only as interfaces in other languages, but also as classes with only parameterless constructor. Whenever there is some code in trait, the trait is called mixin. trait Alarm { def trigger(): String } In scala trait, If we create simple class and pass parameter in constructor, without any val or var, it Continue Reading

ScalaKnol: Understanding Traits as Stackable Modifications

Traits can be used to modify the methods of a class. The way such modifications are carried out is such that they can stack modifications with each other. Let us take an example. Say, there is a class called ImageProcessor which processes images. Now there are a few modifications required before the image is actually uploaded to your server. If you are using Facebook then Continue Reading

Scala Nuggets: Understanding Traits

Inphina provides specialized Scala consulting, training and offshoring … Learn more about Scala@Inphina! If you are coming from a Java background, then traits are interfaces++.  In scala, trait is a complete mixin solution where we can provide implementation in the trait as well as have classes mix-in the trait either when we declare classes or even when we are creating an instance of the class. Continue Reading

%d bloggers like this: