0

Using Lift with Squeryl, how can I make two classes a subclass of the same class?

My classes look like the following:

class SubClass1 extends Record[SubClass1] with KeyedRecord[SubClass1] with CreatedUpdated[SubClass1] {

    val id = ...
    val field1a = StringField(...)
    ...

}

class SubClass2 extends Record[SubClass2] with KeyedRecord[SubClass2] with CreatedUpdated[SubClass2] {

    val id = ...
    val field2a = StringField(...)

}

I want SubClass1 and SubClass2 each to be a child class of some other class, say MyParentClass. So I would think that I would have to do something like this:

abstract class MyParentClass extends Record[MyParentClass] with KeyedRecord[MyParentClass] with CreatedUpdated[MyParentClass] {} 

and then

class SubClass1 extends MyParentClass {

    val id = ...
    val field1a = StringField(...)
    ...
}

class SubClass2 extends MyParentClass {

    val id = ...
    val field2a = StringField(...)
    ...
}

This gives me errors, such as the fields (StringField) etc. not conforming to the right type. Any suggestions on how to do this?

Thanks,

Shafique Jamal
  • 1,550
  • 3
  • 21
  • 45

1 Answers1

1

You abstract superclass can't define a concrete type parameter, since it needs to be overriden by the subclasses. Try:

abstract class MyParentClass[A <: MyParentClass] 
  extends Record[A] with KeyedRecord[A] with CreatedUpdated[A]

Then:

class SubClass extends MyParentClass[SubClass]
Dave Whittaker
  • 3,102
  • 13
  • 14
  • Hello Dave, many thanks for responding. I ended up going with a solution that is very similar to yours: `trait MyParentClass[A <: Record[A]] extends Record[A] with KeyedRecord[A] with CreatedUpdated[A] { self: A => } class MySubClass extends MyParentClass[MySubClass] { ... }` – Shafique Jamal May 26 '15 at 00:52