## Ex10 Task 6: "Overriding" traits does not work

CryNickSystems
BASIC-Programmierer
Beiträge: 119
Registriert: 30. Apr 2015 18:27

### Ex10 Task 6: "Overriding" traits does not work

Hi,

for quite some time I am stuck with the above task.

I simply cannot get my FireAlarm trait working so I can add some logic to the CompositeLocation trait in there.

If I do this:

Code: Alles auswählen

trait FireAlarm extends SmartHome {
trait CompositeLocation[L <: Location] extends super.CompositeLocation[L] with TLocation {
println("Test")
}
}
The println() statement just won't get executed.

I mixin the trait like in the task:

Code: Alles auswählen

class MySmartHome extends SimulatedSmartHome with FireAlarm
Even if I override the abstract types in FireAlarm, it simply doesn't work. Compiles without any problems, but the code inside won't get executed.

CryNickSystems
BASIC-Programmierer
Beiträge: 119
Registriert: 30. Apr 2015 18:27

### Re: Ex10 Task 6: "Overriding" traits does not work

Okay, I fixed it by changing my design a bit.

Capricorn
Windoof-User
Beiträge: 39
Registriert: 29. Apr 2013 12:12

### Re: Ex10 Task 6: "Overriding" traits does not work

Should the FireAlarm trait extend the SmartHome trait? Or asked differently: does it still do in your adjusted design? As far as I can imagine there needs to be some kind of "registration" of the created sensors and actuators, because at the moment all I do is "new SomeSensor" when instantiating a room and nobody knows about the sensors or actuators... or should we delegate that instance creation into a method that as well takes core of wiring the new sensor/actuator together?!

CryNickSystems
BASIC-Programmierer
Beiträge: 119
Registriert: 30. Apr 2015 18:27

### Re: Ex10 Task 6: "Overriding" traits does not work

Yes, I still extend the SmartHome trait.

(And yes, I did try to implement the Stackable Trait pattern [1] for the traits FireAlarm, Lights and Heating)

[1] http://www.artima.com/scalazine/article ... ttern.html

andiderp
Erstie
Beiträge: 20
Registriert: 14. Apr 2012 13:37

### Re: Ex10 Task 6: "Overriding" traits does not work

I tried it aswell but it did not work with the stackable trait pattern. Do you have any hints for me in the right direction?

Thanks
andiderp

ManuelWeiel
Mausschubser
Beiträge: 72
Registriert: 7. Okt 2014 11:38

### Re: Ex10 Task 6: "Overriding" traits does not work

I will try to give a hint without spoiling the solution:

Try to think about what the

Code: Alles auswählen

abstract override def put(x: Int)
method from the stackable traits example would be in your case.
When do you want to run your code in e.g. FireAlarm? Probably after "constructing" your house...