views:

103

answers:

3

Are there any good ways to define interfaces/class hierarchies in a non language specific fashion and then generate corresponding source 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

+3  A: 

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.

Ani
I was considering using UML as I already have access to a number of UML tools. I was kind of hoping that someone would suggest something that allows for some basic code generation insofar as Java and C# have common constructs and basic libraries.
Andy
@Andy: Updated.
Ani
My favorite free, open source, tool for UML is ArgoUML (http://argouml.tigris.org/) it can generate code for Java and C# with the right plugins. It also has critiques to help users make better UML diagrams.
Bill W
+3  A: 

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.

locka
A: 

Take a look at IKVM.NET.

Jordão