Skip to content

Instantly share code, notes, and snippets.

@xnull
Created September 28, 2016 08:41
Show Gist options
  • Save xnull/bbcf46bfa72e3e403654e3fdf13545e6 to your computer and use it in GitHub Desktop.
Save xnull/bbcf46bfa72e3e403654e3fdf13545e6 to your computer and use it in GitHub Desktop.
OOPStyle scala
object MyApp extends App {
val dao = createDaoImpl()
val eventBus = createEventBus()
BusinessLogic(dao, eventBus).foo(123)
}
trait Dao {
def findById(id: Long): String
}
trait EventBus {
def publish(message: String)
}
class BusinessLogic(dao: Dao, eventBus: EventBus) {
def foo(entityId: Long) = {
val entity = dao.findById(entityId)
eventBus.publish(entity)
}
}
object BusinessLogic {
def apply(dao: Dao, eventBus: EventBus): BusinessLogic = new BusinessLogic(dao, eventBus)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment