正如这个问题的标题所暗示的那样:我的问题更多的是形式(惯用惯例)而不是功能.简洁地说:
What is the semantic difference between MyCollectionLike
and MyCollection
?
例如:StringLike和String或MapLike和Map之间有什么区别.仔细观察Scala API文档,我可以看出XLike通常是X的超类型.但除此之外,我不清楚这些抽象层之间的语义差异.
在实践中,如果我正在创建一个新的类/特征,当我为所述类选择名称时,理解这种区别会很有帮助.
我提出的具体问题如下:
I want to create the trait: SurjectiveMap[K,T]
which can be mixed-in with either Map[K,Set[T]]
or MapLike[K,SetLike[T]]
. Given that I do not know the semantic difference between *Like
and *
,I am not sure which to go with.
与IFoo和Foo,Bar和BarImpl之间的区别相同(除了TraversableLike是包含实现的超级特征的事实):
The Scala collection library avoids code duplication and achieves the
“same-result-type” principle by using generic builders and traversals
over collections in so-called implementation traits. These traits are
named with a Like suffix; for instance,IndexedSeqLike is the
implementation trait for IndexedSeq,and similarly,TraversableLike is
the implementation trait for Traversable. Collection classes such as
Traversable or IndexedSeq inherit all their concrete method
implementations from these traits.
从Scala collections architecture