How to require the same parameter type between scala traits? -


i working on web server process registration form , save datastore. want library , work different instances of registration forms.

i have following:

trait registrationform  case class simpleregistrationform(name: string,                                   email: string,                                   username: string,                                   password: string) extends registrationform 

i want subclass of registrationform acceptable server.

i have following traits:

/**   * interface saving datastore   */ trait registrationdatastore[t <: registrationform] {   def save(form: t): either[datastoreexception, string] }   /**   * trait handle form.    */ trait registrationservice[t <: registrationform] {   def handleform(form: t): either[akkahttpextensionsexception, string] } 

and implementation:

class registrationserviceimpl[t <: registrationform](     registrationdatastore: registrationdatastore[t])   extends registrationservice[t] {    def handleform(form: t): either[akkahttpextensionsexception, string] = {      registrationdatastore.save(form)   } 

my server looks this:

object server {       ...       val registrationservice = new registrationserviceimpl[simpleregistrationform]( new registrationmockdatastore[simpleregistrationform]())       ... } 

how can require same form subclass passed type parameters implementations of both registrationservice , registrationdatastore? @ moment, won't both accept independent subclasses of registrationform (i can't test because doesn't yet compile)? e.g. following valid, , if so, how can prevent it?

val registrationservice = new registrationserviceimpl[simpleregistrationform](   new registrationmockdatastore[someotherregistrationform]()) 

how can force compiler make sure same subclass of registrationform?

no, won't valid. constructor parameter registrationdatastore: registrationdatastore[t], when write new registrationserviceimpl[simpleregistrationform](something), something must registrationdatastore[simpleregistrationform].


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -