开发者

Target multiple programming languages/platforms

开发者 https://www.devze.com 2023-01-14 23:10 出处:网络
Are there any good ways to define interfaces/class hierarchies in a non language specific fashion and then generate corresponding source 开发者_StackOverflow中文版code in specified languages? In parti

Are there any good ways to define interfaces/class hierarchies in a non language specific fashion and then generate corresponding source 开发者_StackOverflow中文版code in specified languages? In particular, I need to target both Java and C# for a fairly comprehensive API I am creating. I recall at one point seeing a post here on SF where an answer mentioned a programming language that 'compiled' to other languages-- but I have not been able to find the post. That language may be a solution for what I'm trying to do.

Thanks,

Andy


Have you considered UML? It's easy to find code-generators from UML for lots of different languages (Eg. this one can generate C#, Java and VB.NET code), but you might want to carefully evaluate if it's the right choice for you. As a standard, it has come in for substantial criticism over the years.


Lots of ways of doing something like what you want.

For example you could look at using an interface definition language (IDL). Corba's IDL allows you to declare objects & interfaces in a language neutral way. These idl files are then run through an IDL compiler which outputs the appropriate classes, headers, stubs, proxies etc. for the language of your choice.

For example IIOP.NET is an implementation of Corba for C#. I have no idea how good it is, but it would have an IDL compiler that spits out C# classes. Java has an IDL compiler called idlj as part of the JDK.

In theory therefore you could have C# and Java implemented from the same interfaces & classes.

Another way of doing something similar would be to utilise a UML tool that can generate source code from a model.

Another alternative would be to use something like WSDL / XSD to define your interfaces & types, and generate stubs from that.


Take a look at IKVM.NET. With it, you can write your program in Java (or a JVM language) and transform it into a .NET assembly. So you'll have both a JVM and a .NET version of your program.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号