简体   繁体   中英

Scala: Why do we need to keep type members in the package object?

When I was studying Twitter Finatra (v2.1.1) sources, I found a very odd architecture. They put type s into package object s. See examples below:

package object marshalling {
  @deprecated("MessageBodyManager is an internal class. Use the HttpMockResponses trait to gain access to a testResponseBuilder", "")
  type MessageBodyManager = com.twitter.finatra.http.internal.marshalling.MessageBodyManager

  @deprecated("Use com.twitter.finatra.http.marshalling.DefaultMessageBodyReader", "")
  type DefaultMessageBodyReader = com.twitter.finatra.http.marshalling.DefaultMessageBodyReader

  // ...
}

Or this

package object filters {
  @deprecated("Use com.twitter.finatra.http.filters.AccessLoggingFilter", "")
  type AccessLoggingFilter = com.twitter.finatra.http.filters.AccessLoggingFilter[Request]

  @deprecated("Use com.twitter.finatra.http.filters.CommonFilters", "")
  type CommonFilters = com.twitter.finatra.http.filters.CommonFilters

  // ...
}

I don't understand what is the purpose of such odd design. Why do we need to create a type alias (type member) as in the examples? Just to say that class is deprecated?

This was done in a refactoring commit . You can see there that multiple classes have been moved to new packages, and the type aliases and deprecations were added. For example, DefaultMessageBodyReader was here and then got moved into the internal package. In its original place the alias and deprecation were left.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM