Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
You can add a trait to an individual object when you construct it. To set up an example, we will use the Logged trait that is defined in the standard Scala library. It’s like our Logger, except that it comes with a do-nothing implementation:
trait Logged {
def log(msg: String) { }
}