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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access