Module decoupling

Hi there,

I’m getting my head around modules, and wonder what would be the “CUBA way” to this:

  • Suppose a “crm” module which holds the Party Entity and a PartyService,
  • Now suppose a “collections” module which holds Receivable and ReceivableService.

“collections” does not really much case about “crm”, the only thing it cares about is that a Receivable belongs to a Party. But such a Party might today be provided by “crm” and tomorrow by “crmplus”. “collections” cares about some methods of PartyService and some details of Party (via getters).

On Java land I guess that would be an ideal case for interfaces (for Party and PartyService) to be held outside of “crm” like “crmapi” and that would be the “collections” dependency, thus “crm” can be changed at any time, even “collections” could be reused in another project that has no “crm” but provides a Party / PartyService.

But I’m not sure how that would work with CUBA. On the PartyService it seams clear to me that I can put the service interface in a module, and the implementation on another module and Spring will do its magic and things will work. But, how to do so on the Entity class? Maybe an abstract Entity on the crmapi?

What sideeffects should I be aware of?

Thanks,
marc

PS. I’m on BETA 7 but I think this question is not beta specific so I don’t add the “beta” tag to the post.

Hi Marc,

I think the approach with an abstract entity should work. But it must be an @Entity (not @MappedSuperclass) to be able to have references to it from other entities.

Also, your crmapi module must be an application component to define its own persistence.xml with the abstract BaseParty entity. The app component may not have core and client modules, just global with the persistence.xml and service interfaces.

In the crm implementation app component, you create a Party entity which extends BaseParty. Optionally, it can completely replace BaseParty if you add @Extends annotation to it (“Replace parent” checkbox in Studio). Then all references to BaseParty throughout the application will load and return Party instances.

Regards,
Konstantin

1 Like