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
201k55 gold badges469 silver badges682 bronze badges
asked Oct 16, 2017 at 6:52
0

1 Answer 1

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
201k55 gold badges469 silver badges682 bronze badges
answered Oct 16, 2017 at 18:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.