I have a scala trait as follows -
trait Mytrait {
def saveData : Boolean = {
//make database calls to store
true
}
def getData : Integer = {
//get data from database
return i
}
}
Now I have heard about cake pattern but I am not able to figure out how I can apply cake pattern for mocking traits like this.
Can anyone point out on how this can be done?
You would do it something like this:
where you form the 'layers' or your 'cake' from a suitable DbConnectionFactory and your trait.
This is just a simple example, you could expand on the number of components involved, have multiple implementations of MyTrait that you want to work with under different cirumstances, etc. See, for example Dependency Injection in Scala: Extending the Cake Pattern