简体   繁体   English

Scala / Java中的编程语言抽象

[英]Programming Language Abstraction in Scala/Java

I am currently writing a program using matlab in scala (via the matlabcontrol API). 我目前正在Scala中使用matlab编写程序(通过matlabcontrol API)。 I want to achieve a programming language independent solution, so I can use some algorithms in Scala and some in Matlab. 我想实现一种独立于编程语言的解决方案,因此我可以在Scala中使用某些算法,在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. 该程序已经可以运行(据我测试),但是我也对抽象感兴趣,因此可以使用scilab或其他语言交换模块。

To understand the problem in detail I show you the ImageReader class: 为了详细了解问题,我向您展示了ImageReader类:

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. 我将仅将Scala用作控制器,使用引用,从而为复杂的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. 现在,我还想交换部分代码,并为其他开发人员提供一个可能的切入点,以实现自己的解决方案,例如在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? 如何在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虚拟化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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