Java interfaces

I have a requirement from my team to generate a domain model entirely in Java interfaces.

Anyhow when I draw associations on my class diagrams between my interfaces and then use RoundTrip -> Generate, the java code has private fields for the assocations, which doesn’t compile (see below).

public interface ComputerSystem {
    int getComputerSystemId();
    private Collection<OrganisationalUnit> organisationalUnits;
}

Am I doing something wrong, or is this just not going to work?

Hello xuarlapan,

Would you mind telling me why you need to model with interface + association? As you know, interface should have no association with others. It contains only operations. If you associate an interface with others, the code generater will either ignore the association or generate incorrect code like the one you posted. Both are not desired. Have you ever considered to model with abstract class?

Best regards,
Jick

Thanks for the response.

Well the deal is that the domain model is supposed to be all interfaces to allow different parts of the model to be persisted in different ways.

The associations are represented as operations (getters) on the interfaces, eg

public interface OrderHeader {
  public int getOrderHeaderId();
  // this one is an association
  public Collection<OrderLine> getOrderLines();
  ...
}

public interface OrderLine {
  public int getOrderLine(); 
  ...
}

I know I could model this as abstract classes, but in some cases my implementations have to extend other classes, so it doesn’t work in all cases.

Also it seems rather pointless to have a bunch of abstract classes which contain no implementation whatsoever.

Hi xuarlapan,

I will discuss with our developers and then come back to you.

Best regards,
Jick

Hi xuarlapan,

Glad to inform you that your request is supported in Service Pack 2. You can now model interfaces with association, without generating code for the association. To have the fix, you can update by running the product updater inside the bin folder of VP Suite.

Bset regards,
Jick

Awesome,

haven’t had much time to play with it, but I’ve downloaded it and tried a couple and it looks pretty good.

Thanks for the help, keep up the good work.

Hi xuarlapan,

You are welcome. I hope you find the change helpful.

Best regards,
Jick