Java Reference
In-Depth Information
}
}
There's a lot more work involved in implementing a complete BDD framework, but the pur-
pose of this section is just to show you how to use lambda expressions to create more fluent
domain-specific languages. I've covered the parts of the DSL that interact with lambda ex-
pressions in order to give you a flavor of how to implement this kind of DSL.
Evaluation
One aspect of fluency is the idea that your DSL is IDE-friendly. In other words, you can re-
member a minimal amount of knowledge and then use code completion to fill in the gaps in
memory. This is why we use and pass it the Description and Expect objects. The other al-
ternative would have been to have static imports for methods called it or expect , which is
an approach used in some DSLs. If you pass the object into your lambda expression rather
than requiring a static import, it makes it easier for a competent IDE user to code complete
his way to working code.
The only thing a user needs to remember is the call to describe . The benefits of such an ap-
proach might not be obvious purely from reading this text, but I encourage you to test out the
framework in a small sample project and see for yourself.
The other thing to notice is that most testing frameworks provide a bunch of annotations and
use external magic or reflection. We didn't need to resort to such tricks. We can directly rep-
resent behavior in our DSLs using lambda expressions and treat these as regular Java meth-
ods.
Lambda-Enabled SOLID Principles
The SOLID principles are a set of basic principles for designing OO programs. The name it-
self is a acronym, with each of the five principles named after one of the letters: Single re-
sponsibility, Open/closed, Liskov substitution, Interface segregation, and Dependency inver-
sion. The principles act as a set of guidelines to help you implement code that is easy to
maintain and extend over time.
Each of the principles corresponds to a set of potential code smells that can exist in your
code, and they offer a route out of the problems that they cause. Many topics have been writ-
ten on this topic, and I'm not going to cover the principles in comprehensive detail. I will,
Search WWH ::




Custom Search