简体   繁体   中英

Programming Language Abstraction in Scala/Java

I am currently writing a program using matlab in scala (via the matlabcontrol API). I want to achieve a programming language independent solution, so I can use some algorithms in Scala and some in Matlab. The program works already (as far as I tested it) but I am also interested in abstraction so that I can exchange modules using scilab or other languages.

To understand the problem in detail I show you the ImageReader class:

trait ImageReader {
  def readImage(path:String):Any
}

object Matlab_ImageReader extends ImageReader {
  def readImage(path:String):Any = {
     proxy.eval("image = imread('"+ path + "');"
     return "image"
  }
}

The idea is, that I want to treat the return value as a reference to the language object I use. I will use Scala only as a controler, working with references and thereby implementing a partwise object-oriented solution for a complicated piece of matlabcode.

Now I also want to exchange parts of the code and give other developers a possible entrypoint for implementing their own solution for example in Scala. The problems are:

  1. How to return a concrete and mutual Datatype, so I can use the method knowing I will always have the same return-type?
  2. How to get a reference to a value in Scala? It would help me a lot as I may be able to abstract it this way.

I am sorry for the vague question, but I do not really know how to explain my exact problem :)

也许您应该看看轻量级模块化分段Scala虚拟化

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM