concept class in category scala

appears as: classes, class, class, A class, The classes, The class, classes
Get Programming with Scala

This is an excerpt from Manning's book Get Programming with Scala.

An Object-Oriented programming language has a structure based on classes and subclasses. They have well-defined behaviors, and they exchange information through methods. Listing 1.1 provides an example of how to define a class:

Listing 1.1: MyClass example
// our first Scala example //#A
class MyClass(name: String) { //#B
  def sayHello(otherName: String) = 
s"Hi $otherName, my name is $name!" //#C
}

In lesson 7, you’ll learn how to define classes and subclasses. In lesson 20, you will also discover a particular type of class to present data in an immutable manner, called “case class”.

Singleton instances are instances that you should initialize at most once. Scala offers a dedicated syntax for them: you usually refer to them as “objects”. Do not be confused by the term “object” as it can refer to an instance of a class rather than a singleton in other languages. In lesson 11, you’ll learn about singleton objects in Scala and how not to be confused by the terminology. Listing 1.2 shows you an example of a singleton – or “object” – in Scala:

Figure 7.1: Syntax Diagram on how to define and initialize a class in Scala.

In lesson 9, you have learned about packages. Especially when creating external modules for third parties to use, you shouldn’t make every fragment of your code accessible. By protecting the access parts of your application, you reduce the entry points of your package, which makes it easier to use. By doing so, you can also prevent external manipulations that could expose sensitive data or introduce undesired behavior. In this lesson, you will learn about the Scala access modifiers, which are reserved keywords to change the visibility of your code elements. You should use them to protect and hide information that you should not expose to the public. In the capstone, you will use access modifiers to implement auxiliary functions that are accessible only from the class you declared them in.

scala> exchangeRateUSD(CAD)
scala.MatchError: CAD$@30437e9c (of class CAD$)
  at .exchangeRateUSD(<console>:19)
  ... 28 elided