O'Reilly logo

Building Applications with Scala by Diego Pacheco

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

Refactoring services

We need to change the default base trait for our dao packages to return Futures now.

Let's start with BaseServices.scala:

    package services 
    import scala.concurrent.Future 
    trait BaseService[A] { 
      def insert(a:A):Future[Unit] 
      def update(id:Long,a:A):Future[Unit] 
      def remove(id:Long):Future[Int] 
      def findById(id:Long):Future[Option[A]] 
      def findAll():Future[Option[Seq[A]]] 
    } 

This last implementation reflects what's happening in the dao packages. Now we can move to the services implementation, and proceed with our refactoring.

Next we see ProductService.scala:

 package services trait IProductService extends BaseService[Product]{ def insert(product:Product):Future[Unit] def update(id:Long,product:Product):Future[Unit] def remove(id:Long):Future[Int] ...

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