What are the pros of using traits over abstract classes?

前端 未结 7 1456
-上瘾入骨i
-上瘾入骨i 2021-01-30 10:12

Can someone please explain traits in Scala? What are the advantages of traits over extending an abstract class?

相关标签:
7条回答
  • 2021-01-30 10:40

    This is the best example I've seen

    Scala in practice: Composing Traits – Lego style: http://gleichmann.wordpress.com/2009/10/21/scala-in-practice-composing-traits-lego-style/

        class Shuttle extends Spacecraft with ControlCabin with PulseEngine{
    
            val maxPulse = 10
    
            def increaseSpeed = speedUp
        }
    
    0 讨论(0)
提交回复
热议问题