讓我們看看幾個單獨的DAO類OrderDAO
,ProductDAO
和CustomerDAO
,它們在數據庫中存儲/檢索數據並共享單個實例DataSource
(數據庫連接工廠)。關於蛋糕模式的問題
爲了創建DataSource
實例並將其插入DAOs
,我們通常使用Spring DI。現在我想在沒有任何DI框架的Scala中這樣做。
我讀過有關cake pattern,它看起來像我應該做到以下幾點:
trait DatabaseContext { val dataSource:Datasource }
trait OrderDAO {this:DatabaseContext =>
... // use dataSource of DatabaseContext
}
trait ProductDAO {this:DatabaseContext =>
... // use dataSource of DatabaseContext
}
object DAOImpl extends OrderDAO with ProductDAO with DatabaseContext {
val dataSource = ... // init the data source
}
我是否正確理解了蛋糕的圖案?
我可以使用蛋糕圖案以不同方式實施這些DAOs
嗎?
它提供了像Spring這樣的DI框架嗎?
如何創建單獨的OrderDAOImpl
和ProductDAOImpl
對象共享相同DataSource
實例而不是一個大DAOImpl
?
我簡要閱讀了關於蛋糕模式,並沒有看到興奮是關於什麼。看起來比現有的DI容器複雜得多。 – Kevin 2011-04-15 17:06:48