views:

838

answers:

2

Quick Note: Examples from this tutorial.

Suppose I have the following Traits: Student, Worker, Underpaid, Young

How could I declare a class (not instance) CollegeStudent with all these traits?

Note: I am aware of the simplests cases, such as CollegeStudent with one or two Traits:

class CollegeStudent extends Student with Worker
+5  A: 

Actually, this is easy...

class CollegeStudent extends Student with Worker with Underpaid with Young
Daniel Ribeiro
+13  A: 

It is easy, when declaring a class you just use the "with" keyword as often as you want

class CollegeStudent extends Student with Worker with Underpaid with Young

the order of the traits can be important if a trait is changing the behavior of the class, it all depends on traits you are using.

Also if you don't want to have a class which always uses the same traits you can use them later:

class CollegeStudent extends Student
new CollegeStudent with Worker with Underpaid with NotSoYoungAnymore
Alexander Stolz