Object-Oriented Scala

"The object-oriented model makes it easy to build up programs by accretion. What this often means, in practice, is that it provides a structured way to write spaghetti code."

- Paul Graham

In the previous chapter, we looked at how to get programming started with Scala. Well, if you're writing the procedural program that we followed in the previous chapter, you can enforce the code reusability by creating procedures or functions. However, if you continue working, consequently, your program gets longer, bigger, and more complex. At a certain point, you will not even have any other more simple way to organize the entire code before production.

On the contrary, the object-oriented programming (OOP) paradigm provides a whole new layer of abstraction. You can then modularize your code through defining OOP entities such as classes with related properties and methods. You can even define the relationship between those entities by utilizing inheritance or an interface. You can also group similar classes holding similar functionality together, as a helper class maybe; therefore, making your project suddenly feels more spacious and extensible. In short, the greatest strengths of OOP languages are discoverability, modularity, and extensibility.

Considering the preceding features of OOP languages, in this chapter, we will discuss the basic object-oriented features in Scala. In a nutshell, the following topics will be covered in this chapter:

  • Variables in Scala
  • Methods, classes, and objects in Scala
  • Packages and package objects
  • Traits and trait linearization
  • Java Interoperability

Then, we will discuss pattern matching, which is a feature that comes from functional programming concepts. Moreover, we will discuss some built-in concepts in Scala, such as implicit and generics. Finally, we will discuss some widely used build tools that are needed for building our Scala applications into jars.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.163.208