0

I've been reading a bit about the Cake Pattern in Scala (I know that is old stuff), and I cannot see or imagine an way to lock down the concrete classes, so dependencies don't leak from the classes where they are injected.

A simple and current example comes from the play-reactive-mongo-db activator template. In that app, the controllers use the ReactiveMongoComponents trait to get an instance of the driver ReactiveMongoApi.

Now, the problem is that the controller inherits has a public method to return an instance of reactiveMongoApi and as such breaking 2 fundamental principles: Encapsulation and Information Hiding. I know the example is not great (as a controller shouldn't access any data store), but the same applies if there would be domain services or repositories. I know that those classes (domain services, repositories, etc) would have a trait that defines the accessible methods, and there wouldn't be a public method/attribute to get the dependency, but the concrete implementation does leak.

TL;DR: Cake pattern leaks dependencies from concrete implementations, how can this be avoided?

Augusto
  • 28,839
  • 5
  • 58
  • 88
  • 1
    OK, this really isn't an answer to your question, but one approach is to [scrap your cake pattern](http://blog.originate.com/blog/2013/10/21/reader-monad-for-dependency-injection/). – jwvh Jul 18 '16 at 07:18
  • Thanks for the suggestion @jwvh, I'll give that blog a good read and try to use it in one of my pet projects. – Augusto Jul 18 '16 at 09:52

0 Answers0