假设如下:
/**
* the importer trait that glues extractor , transformator and loader together
* (mini etl)
*/
trait Importer[A, B, C] {
//this makes sure that the importer
//implements an extractor, a transformator and a loader (selfytping)
self: Extractor[A, B] with Transformator[B, C] with Loader[C] =>
/**
* this is the method call for chaining all events together
*/
def importAndTransformData(dataSource: A): Unit =
{
/**
* perform initializations if necessary
*/
initializeExtractor
/**
* extraction step
*/
val output = extract(dataSource: A)
/**
* before the loading takes place we initialize the Loader if required
*/
initializeLoader
/**
* conversion method that gets injected the load method
*/
val transformed = transform(output, load)
/**
* perform actions afterwards if required
*/
cleanupExtractor
cleanupLoader
}
初始化方法目前有一个虚拟实现什么都不做。如果需要,由具体的特征/子类来覆盖它。这似乎有点笨拙。
有更好的方法吗?