score:0

Accepted answer

Some quick ones:

Those _ parameters you pass in and then immediately assign to vals: why not do it in one hit? e.g.

abstract class Synchable( val ruid: String = "", val lastSyncTime: String = "",  val isDeleted: Int = 0) {

which saves you a line and is clearer in intent as well I think.

I'm not sure about your defaulting of Strings to "" - unless there's a good reason (and there often is), I think using something like ruid:Option[String] = None is more explicit and lets you do all sorts of nice monad-y things like fold, map, flatMap etc.

Looking pretty cool otherwise - the only other thing you might want to do is strengthen the typing with a bit of this.type magic so you'll prevent incorrect usage at compile-time. With your current abstract class, nothing prevents me from doing:

class SynchableCat extends Synchable { ... }
class SynchableDog extends Synchable { ... }

val cat = new SynchableCat
val dog = new SynchableDog

cat.updateWith(dog) // This won't end well

But if you just change your abstract method signatures to things like this:

def updateWith(target: this.type)

Then the change ripples down through the subclasses, narrowing down the types, and the compiler will omit a (relatively clear) error if I try the above update operation.


More Query from same tag