Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Programming in Scala > Chapter 25: The Architecture of Scala Collections - Pg. 573

Chapter 25 The Architecture of Scala Collections This chapter describes the architecture of the Scala collections framework in detail. Compared to what you learned in Chapter 24 you will find out more about the internal workings of the framework. You will also learn how this architecture helps you define your own collections in a few lines of code, while reusing the overwhelming part of collection functionality from the framework. Chapter 24 enumerated a large number of collection operations, which exist uniformly on many different collection implementations. Implementing every collection operation anew for every collection type would lead to an enormous amount of code, most of which would be copied from somewhere else. Such code duplication could lead to inconsistencies over time, when an operation is added or modified in one part of the collection library but not in others. The principal design objective of the new collections framework was to avoid any duplication, defining every operation in as few places as possi- ble. 1 The design approach was to implement most operations in collection "templates" that can be flexibly inherited from individual base classes and implementations. This chapter explains these templates and other classes and traits that constitute the "building blocks" of the framework, as well as the construction principles they support. 1 Ideally, everything should be defined in one place only, but there are a few exceptions where things needed to be redefined. 573