【发布时间】:2016-03-04 12:07:23
【问题描述】:
我正在从本书Scala in Action 中学习 Scala,在这一章中作者正在解释 Traits。解释有以下代码块,其中我无法弄清楚Trait definitionnof Updatable中-=和+=的含义@
请帮忙!
package com.scalainaction.mongo
import com.mongodb.{DBCollection => MongoDBCollection }
import com.mongodb.DBObject
class DBCollection(override val underlying: MongoDBCollection)
extends ReadOnly
trait ReadOnly {
val underlying: MongoDBCollection
def name = underlying getName
def fullName = underlying getFullName
def find(doc: DBObject) = underlying find doc
def findOne(doc: DBObject) = underlying findOne doc
def findOne = underlying findOne
def getCount(doc: DBObject) = underlying getCount doc
}
trait Updatable extends ReadOnly {
def -=(doc: DBObject): Unit = underlying remove doc
def +=(doc: DBObject): Unit = underlying save doc
}
【问题讨论】: