Created
September 28, 2016 08:41
-
-
Save xnull/bbcf46bfa72e3e403654e3fdf13545e6 to your computer and use it in GitHub Desktop.
OOPStyle scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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