In Java
I would typically declare my entire domain as interface
s, possibly with some kind of Factory
to get me implementations. This is partly because I am so old I can remember when some persistence layers required implementation classes to subclass a specific class but also so that I can easily:
- mock objects for testing purposes
- proxy objects at runtime if necessary
- provide different implementations
I follow this practice even when I don't really envisage that I'll actually want to do any of the above; I still believe it to be good practice just in case. I think it's a fairly common approach.
Would this be unusual in Scala-land if I declare all domain objects abstract
? Do the points above hold for Scala as well?