2
我正在從書Scala in Action
學習Scala,在本章中作者正在解釋Traits。解釋有以下代碼塊,其中我無法弄清楚特徵定義中的 - =和+ =的含義Updatable
- =和+ =在Scala中的含義特徵定義
請幫助!
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
}