Summary

Lazy acquisition is a pretty commonly used pattern. The proxy design pattern is a nice example of Lazy Acquisition. ORM frameworks like Hibernate use proxies for lazy loading. Scala pushes the envelope by providing lazy vals and streams, which provide for on-demand computation, using thunks. Memoization is a related pattern to avoid computing the same value again. Instead, the value is cached. Java's autoboxing classes use memoization to conserve memory. Scala's streams use memoization and strike a balance between on-demand computation and memoization. Call by name is another powerful technique for delayed evaluation of code.

Let's now try mixing in some traits to our bag of Scala techniques in next chapters. Traits are Java interfaces ...

Get Scala Functional Programming Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.