O'Reilly logo

Scala Design Patterns - Second Edition by Ivan Nikolov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing our code

We will create an application that can read from a database data about people, classes, and who has signed up to which classes. We will have a user service which will implement some simple business logic with the data, and a service that will access the data. It will be a small application, but it will clearly show how dependency injection works.

Let's start with the simple stuff. We will need to have a model for the objects that we will be representing:

case class Class(id: Int, name: String)case class Person(id: Int, name: String, age: Int)

In the preceding code, we have two classes that will be used in our application. There is nothing special about them, so let's go further.

We said that we want our application to be ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required