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.