0

I've decided to implement a database wrapper to provide data operations of a web service using postgresql dbms.

Models in my database are somelike complex and frameworks like slick do provide more problems and need of workarounds due to type complexity than time or effort saving.

Following this Programming in Scala 2 quote:

Traits are a fundamental unit of code reuse in Scala. A trait encapsulates method and field definitions, which can then be reused by mixing them into classes. Unlike class inheritance, in which each class must inherit from just one superclass, a class can mix in any number of traits

I'm implementing this wrapper as a trait.

A couple of questions arise:

Does anyone out there recommend me to implement this using another scala structure?
Is anyone successfully using a database abstraction library for postgresql while programming in scala?

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
Evhz
  • 152
  • 8

1 Answers1

1

You can implement it as a trait. The question is, why do you want to?

Traits are not intended to be used on their own. They are intended to be mixed together with other traits, into a class. You haven't talked at all about what other traits your wrapper might potentially be mixed with, in different combinations, or what kinds of classes might want to mix in your wrapper trait. If you don't have those kinds of use cases already in mind, there's no reason not to go with a class.

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
Karl Bielefeldt
  • 146,727
  • 38
  • 279
  • 479