Why use scala's cake pattern rather than abstract fields?

前端 未结 4 854
孤街浪徒
孤街浪徒 2020-12-15 04:51

I have been reading about doing Dependency Injection in scala via the cake pattern. I think I understand it but I must have missed something because I still can\'t see the

4条回答
  •  情深已故
    2020-12-15 05:34

    In this example I think there is no big difference. Self-types can potentially bring more clarity in cases when a trait declares several abstract values, like

    trait ThreadPool {
      val minThreads: Int
      val maxThreads: Int
    }
    

    Then instead of depending on several abstract values you just declare dependency on a ThreadPool. Self-types (as used in Cake pattern) for me are just a way to declare several abstract members at once, giving those a convenient name.

提交回复
热议问题