0

I need to make a decision to keep only identifier of another class or an object reference to it within another class. The situation is as follows:

public class Article {
    private int ownerId;
}

or:

public class Article {
    private User owner;
}

And here comes the problem:

  1. I have separated my domain classes into another module (say domain, and the rest of the project is in core), this is because this domain module can be imported by some users (Drools Workbench users who design processes)
  2. The Article class is in the domain module.
  3. domain module is not dependent on Spring security, but the core is.
  4. If I will use an object reference in Article I will have to include Spring Security as a Maven dependency to domain module (because private User owner is a Spring Security User), which will make it significantly greater in size.
  5. I don't quite want my domain module to be a big jar file, because it makes it hard to include in Drools, or even more around within company.

So, what might be the correct way to go in this situation? Normally, I would go for the object reference for the obvious reasons that can be found here as well, but I am inclined to make an exception for this case.

Hasan Can Saral
  • 2,950
  • 5
  • 43
  • 78
  • This is just an opinion and I do not know if it suits you, but I would separate the `core` project into two projects, one with the classes that do not need the Spring Security, and other with the ones that need it (and maybe call it `core-spring`). – jeojavi Jun 25 '17 at 17:57
  • @JaviFernández The problem is not in `core` but in `domain`. I can separate `domain` into two `domain` and `domain-spring`, but then again it wouldn't help a lot since `domain-spring` requires Spring Security and ends up as quite a fat jar. Did I get you correctly? – Hasan Can Saral Jun 25 '17 at 18:09
  • 1
    Sorry Hasan, I think I didn't explain myself correctly. What I mean is that you can separate the `core` project into two projects (for example `core` and `core-spring`), and the project `domain` would only include de `core` project as dependency. In this way you have three projects: `core`, `core-spring` that depends on `core`, and `domain` which also depends on `core`. The `core` project would contain only the common code for `core-spring` and `domain` projects. – jeojavi Jun 26 '17 at 08:07
  • Oh I see, it's just naming that confused me. In my case, `core` depends on `domain` since it's the module with services etc. and `domain` is just a jar to be imported in Drools. I understand you now, it's a similar solution to the one in answer. Thanks! – Hasan Can Saral Jun 26 '17 at 08:10

1 Answers1

1

A possible solution can be found extending the Article domain object in the package you need, attaching to extended version the information you need (a sort of Decorator)