This article provides a technical comparison between using the cake pattern and constructor injection for doing dependency injection in Scala. I show that within a small handful of refactoring steps, we can migrate from the cake pattern to constructor injection. We lose one minor feature along the way. The lost feature is not terribly desirable anyway, and can be emulated with constructor injection if need be. In exchange, we jettison the boilerplate and the opaque nature of the cake pattern.
Showing posts with label cake pattern. Show all posts
Showing posts with label cake pattern. Show all posts
2014-12-15
2014-10-05
Catching Up: Writing Again!
So I just finished up this blog post, Just What the Heck is Amortized Constant Time Anyway?, over the last couple weeks. And I felt odd once I finally posted it, because of the total lack of personal context as to where this post is coming from. After all, it's been over a year since my previous post. So I wanted to write a quick "catching up" post, which is mostly about the fact the I am writing again!
2013-06-26
Scala Days Recap and Video
Recap
I really had a blast at Scala Days this year. I met so many wonderful people, saw many wonderful talks, and had a ton of fun. I met so many great people, I can't possibly mention them all. My best memory is drinking a glass of wine at a bar with all the Scala Days attendees, when from out of the blue come Matthias Nehlsen to greet me. We have known each other on Google+ for some time, but had never met before in person. It felt like one of those Dora episodes where they all jump into the Fairy Book and go to Fairy Land.I also got to speak to Dick Wall a bit, which was sort of a Wayne's World moment for me ("We're not worthy!"), as I used to be an avid Java Posse listener before I started writing mostly Scala. Great podcast that really helped me keep in touch with what was going on in the Java community. For Scala, I listen to the Scalawags, and I eagerly look forward to the resumption of the Scala Types podcast.
I really loved Rod Johnson's keynote. Scala poetry is a beautiful idea. I'll try to write some one day. The only point in his keynote that I question is that startups are not going to be using Scala. I don't object out of reason, but from the observation that there are many startups in the Cambridge/Boston area that are taking up Scala. There were too many great talks to start telling stories, but I won't forget asking a stupid question at Heather Miller's Pickles and Spores talk for a while. There are still many talks that I need to catch up with online. In many slots it was hard to pick between sessions!
2013-05-07
Proof of Concept: Cake Pattern Type Macros
I've been using spare cycles over the last six weeks to try to put together a proof of concept implementation of the type macros I described in my Taming the Cake Pattern blog post from three months ago. I'm happy to say I have a working implementation of the first six macros! It really needs at least one more to be at all useful, and there is plenty of stuff that needs to be fleshed out. But I was very happy to learn that it was actually possible to make this happen. I'm currently compiling three examples and 27 test cases.
2013-03-08
Taming the Cake Pattern with Type Macros
In a previous post we discussed various techniques that could be employed with the component based dependency injection (CBDI; typically referred to as the cake pattern). In particular, we discussed two CBDI features that are not available in DI frameworks such as the Spring framework or Google guice: expressing design constraints between hierarchical components, and encapsulating the details of a composite component. Alongside these advantages, however, the cake pattern has some disadvantages that limit its appeal. The three major problems that I see are:
Lately I've been pretty excited about type macros, an experimental Scala language feature, and I've been considering ways in which type macros might relieve some of these problems. In this blog post, I want to describe some hypothetical type macros that might alleviate the first two problems: verbosity and opacity. I haven't had a chance to use Scala macros yet, and while the macros presented here should be possible, I can't say for sure until I've tried it. So think of what is presented here as a spec. I'm going to try to implement it, and I'll let you know how that goes.
- Verbose: Lots of boilerplate.
- Opaque: It's hard to figure out and understand what is going on by looking at the code because the language structures used do not signify the user's intent. These language structures are somewhat advanced, and may seem a bit foreign to programmers that are relatively new to Scala.
- Aloof: Compiler error messages are potentially confusing and misleading, because they address the language structures used, and not the user's intent.
Lately I've been pretty excited about type macros, an experimental Scala language feature, and I've been considering ways in which type macros might relieve some of these problems. In this blog post, I want to describe some hypothetical type macros that might alleviate the first two problems: verbosity and opacity. I haven't had a chance to use Scala macros yet, and while the macros presented here should be possible, I can't say for sure until I've tried it. So think of what is presented here as a spec. I'm going to try to implement it, and I'll let you know how that goes.
2013-02-12
Component Based Dependency Injection in Scala
I recently wrote up my experiences using the "cake pattern" for dependency injection in Scala. It grew into quite a lengthy write-up, so I wanted to share it as a PDF in case reading in this blog format is inconvenient:
The same content appears below, but please be warned that the internal links are broken, and the code formatting is not to my liking:
Subscribe to:
Posts (Atom)