concept interface in category scala

appears as: interfaces, interface, n interface, interface, The interface, interfaces
Get Programming with Scala

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

A class can only have one superclass. In unit 2, you’ll learn how to express multiple-inheritance using traits, which are the equivalent of interfaces in other object-oriented programming languages.

You can use traits to define interfaces to represent a set of features (hence the name “traits”) that your class must have: this is a crucial object-oriented concept that you find in many languages, such as Go, Kotlin, and Java. In future units, you will learn that traits are a lot more than just a way to express an interface: you’ll see some of their superpowers and why this makes them a more expressive and powerful tool. In this lesson, you’ll discover how to create a trait and how to implement classes, objects, and other interfaces that conform to one or more interfaces. You’ll also learn about sealed traits: they allow you to define a closed set of implementations for your interface that the compiler guarantees at compile time. In the capstone, you’ll use the App trait to implement the entry point of your application.

Suppose you need to represent the animals of a zoo and make sure they all some behavior in common: they all sleep, eat and move. Let’s define an interface to enforce these functionalities. Listing 12.1 shows you how to achieve this using a trait:

Listing 12.1: The trait Animal
trait Animal {
 
    def sleep = "ZzZ" 
 
    def eat(food: String): String
 
    def move(x: Int, y: Int): String
  }

In Scala, use the keyword trait and a name to identify an interface. A trait cannot have parameters, but it can have both abstract and fully implemented coding elements, such as functions, values, variables. Listing 12.2 provides another example of a trait:

Figure 12.1: Syntax diagram of how to define a trait in Scala: you can use them to implement interfaces.
Lift in Action: The Simply Functional Web Framework for Scala

This is an excerpt from Manning's book Lift in Action: The Simply Functional Web Framework for Scala.

User behavior online in recent years has changed; people now spend more time than ever online, and this means they want the way they interact with online services to be more intuitive and natural. But building such rich applications has proven to be tough for many developers, and this often results in interfaces and infrastructures that aren’t really up to the job or user expectations. Lift aims to make building real-time, highly interactive, and massively scalable applications easier than it has ever been by supporting advanced features like Comet, which allow you to push data to the browser when it’s needed, without the user having to make any kind of request for it.

This isn’t the end of the story. If you run the code as it is now, you’ll notice that it does indeed update the database and insert the new bid, complete with auction and customer references. The interface, however, isn’t updated. This is intentional. In the next section, we’ll be covering Comet, and the bidding values will be updated from the CometActor, along with a real-time countdown.