Scala tag syntax

I look through the documentation for Scalatra and notice an interesting piece of code for syntax that I have not seen yet: http://www.scalatra.org/2.2/guides/persistence/introduction.html

In particular, this is a bit:

trait DatabaseSessionSupport { this: ScalatraBase => import DatabaseSessionSupport._ 

everything here makes sense except for the this: ScalatraBase => segment. What does it mean here? Is it specific for imports below or for the whole attribute?

+6
source share
1 answer

This is called a "self-tuning annotation" and requires that any use of trait DatabaseSessionSupport in the instance class must be accompanied by a ("mixed with") type consistent with ScalatraBase . I did not consider this specific code, but most likely it uses the so-called "cake pattern".

You can find many methods of this concept both in stack overflow, and in various blogs and in the classic work of Odersky et. et al., entitled " Scalable Component Abstractions ."

+5
source

Source: https://habr.com/ru/post/947262/


All Articles