Hacker News new | ask | show | jobs
by oselhn 3781 days ago
Trait in scala represents interface (your type understands some message) or "is a" relation (your type is more specific specialization of type). In your example it is not the case (Tywin is Jamie's father, which should be solved by composition). I do not think that Tywin, Jamie etc. is separate type. In my opinion, those are instances of some type. It is not good practise to call super implementation of method either. You are mixing inheritance and overriding, which in more complex programs always cause trouble (you may break inherited method by changing super implementation). You should solve this by composition (Jamie should not inherit Tywin addToDebt but should depend on Tywin for paying his depts).

I understand what you wanted to show but your example is really confusing and definitely is not correct.

1 comments

I agree its not a real life example :) It was never meant to be. And definitely there is some better approach to implement the same hierarchy.