Chapter 2. Scala for functional domain models

 

This chapter covers

  • Understanding why Scala is one of the better languages for domain modeling
  • Understanding the benefits of domain modeling using a statically typed language
  • Combining the OO and FP power of Scala to achieve modular and pure models

Now that you’re familiar with the basic concepts of functional and reactive domain modeling, how will you go about implementing such a model? And when you think about implementation, you must think about which language to use. Many languages provide enough power to implement expressive domain models. This book uses Scala, an object-functional language that’s statically typed, runs on the Java virtual machine (JVM), and offers excellent interoperability with Java.

But you may wonder, why Scala? What special features does Scala offer that make it an attractive proposition for domain model implementation? You’ll learn some of those features in this chapter and see how they help in specific aspects of building the model. Scala has both object-oriented (OO) and functional capabilities, which turn out to be a powerful combination in implementing and organizing domain models. You’ll use the functional power of Scala to implement immutable data and domain behaviors, and you’ll use its OO capabilities to modularize your domain models.

2.1. Why Scala?

 
 
 
 

2.2. Static types and rich domain models

 

2.3. Pure functions for domain behavior

 
 
 

2.3.1. Purity of abstractions, revisited

 
 
 

2.3.2. Other benefits of being referentially transparent

 
 

2.4. Algebraic data types and immutability

 
 
 

2.4.1. Basics: sum type and product type

 

2.4.2. ADTs structure data in the model

 

2.4.3. ADTs and pattern matching

 
 

2.4.4. ADTs encourage immutability

 

2.5. Functional in the small, OO in the large

 
 

2.5.1. Modules in Scala

 

2.6. Making models reactive with Scala

 
 

2.6.1. Managing effects

 

2.6.2. Managing failures

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage