Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kMolecules DDD flavor of jMolecules DDD to work around issues in Kotlin #51

Closed
jntakpe opened this issue May 20, 2021 · 13 comments
Closed
Assignees
Labels
module: ddd Domain-Driven Design related support type: enhancement New feature or request
Milestone

Comments

@jntakpe
Copy link
Contributor

jntakpe commented May 20, 2021

jMolecules DDD types are helping a lot but there are some annoying limitations due to Kotlin's Java interoperability.

The main limitation is due to Identifiable#getId method that conflicts with constructor's id field as shown below:

//Won't work as Kotlin's generated getter has the same signature as Identifiable#getId method
class Conflict(val id: Id, val other: String): Entity<Portal, Id> {
    override fun getId(): Id = id
}
// Won't work as id 'overrides nothing'
class Override(override val id: Id, val other: String): Entity<Aggregate, Id>

Obviously it is possible to rename constructor's id field but it makes framework integration brittle since projects such as the excellent Spring Data instantiates objects via constructor if I'm not mistaken. It also hurts Kotlin's conciseness and integrate poorly with Kotlin's data classes.

To cope with those issues I created Kotlin counterparts for jMolecules DDD types. I would be happy to contribute a PR if you think it makes sense

@jntakpe jntakpe changed the title Better Kotlin supports Better Kotlin support May 24, 2021
@odrotbohm odrotbohm assigned odrotbohm and unassigned odrotbohm Jun 9, 2021
@odrotbohm odrotbohm added the lifecycle: waiting-for-feedback Feedback by the original reporter needed label Jul 15, 2021
@odrotbohm
Copy link
Member

You seem to run into this ticket which – unfortunately – hasn't seen any significant progress since it was filed 6 years ago. I can certainly take the suggestion forward to the team but my gut reaction is that I (we) don't want to introduce and maintain an additional artifact replicating another artifact, just to fix a problem in the target language.

The linked ticket has a suggestion of how to make this work using inline and actually declared methods. I know this is not as elegant as it could be, but I don't see why the proclaimed elegance of a language should create significant overhead library authors of a language they allegedly integrate seamlessly with.

@jntakpe
Copy link
Contributor Author

jntakpe commented Jul 15, 2021

Ok ! It makes sense. I will most likely create a fork to ease Kotlin integration for Kotlin users

@odrotbohm
Copy link
Member

I gave this a bit more thought and briefly thought it might be okay to just coin a new kMolecules project and repo and ship something similar to what you proposed in your PR, assuming someone was willing to contribute and maintain any of this.

But what the occurred to me is that virtually everything in jmolecules-integrations would need to be either copied over or needed to be made aware of the Kotlin re-declarations of the artifacts. That currently seems like a bad tradeoff between gain and cost, given that nobody of the team has significant expert experience with Kotlin to avoid running into language-specific gotchas or the time to basically replicate and keep the port of all the integrations up to date.

@odrotbohm
Copy link
Member

Word is on the street that we might see movement on the related ticket in Kotlin soon. In that light, I'd refrain from moving forward with anything Kotlin specific, as I expect it to be just working with the Java-based abstractions as is.

@jntakpe
Copy link
Contributor Author

jntakpe commented May 2, 2022

Waiting for a decision I've created a library that mimics jmolecules-ddd with types easier to use in Kotlin here

@odrotbohm
Copy link
Member

That's wonderful, thanks! I can take this to our team meeting this afternoon. Would you be generally interested in moving this repo to the xMolecules org?

@jntakpe
Copy link
Contributor Author

jntakpe commented May 2, 2022

Yes sure !

@odrotbohm
Copy link
Member

There have been a few thoughts and questions coming up in the team call, that I would like to forward:

  • We would like to move to a org.jmolecules:kmolecules-ddd artifact identifier to make the switch as simple as changing the j into a k for the artifact identifier.
  • Question remains whether this should be a separate repository or could just be a separate module in the current jmolecules repository. The latter would make it easier to release and avoid the JAR being "something separate" but would ultimately require the build to switch to Maven. Is that something you would be okay with?
  • We were wondering whether we could use the identical package name (org.jmolecules.ddd) as that would allow existing integrations to pick up the Kotlin-based annotations and interfaces without additional need for integration. That of course assumes that only one of the two would ever be on a project's classpath, and the methods exposed by the interfaces semantically equivalent to the Java counterparts. Do you think that would cause any problems?

@jntakpe
Copy link
Contributor Author

jntakpe commented May 6, 2022

Ok

  • Regarding your first point sure no problem.
  • No problem to switch to Maven. The GH-51 Better Kotlin integration #52 is already built with Maven
  • Regarding the last to be able to provide a correct answer I should run some test with the different integrations. But sure if it works it is way better to do it that way.

However I won't be able to work on it for the next two weeks

@odrotbohm
Copy link
Member

I gave this a quick spin, and it seems to work as expected. I would go ahead and commit the types you created into the tweaked module setup, with you as the official committer and take it from there?

odrotbohm pushed a commit that referenced this issue May 6, 2022
The type-based flavor of the DDD building blocks uses methods that follow the Java Beans naming convention. Unfortunately, Kotlin currently does not implement these methods if properties are declared that match the convention [0]. This commit adds a kmolecules-ddd module that completely defines the same abstractions as jmolecules-ddd in Kotlin so that they can be properly used from Kotlin as well.

The types are located in the org.jmolecules.ddd package so that we can phase out this module as soon as that glitch in Kotlin is fixed and users can just drop this JAR here in favor of the jMolecules DDD one.

[0] https://youtrack.jetbrains.com/issue/KT-6653
@odrotbohm odrotbohm removed lifecycle: waiting-for-feedback Feedback by the original reporter needed lifecycle: for-team-discussion labels May 6, 2022
@odrotbohm odrotbohm added this to the 1.5 milestone May 6, 2022
@odrotbohm odrotbohm added type: enhancement New feature or request module: ddd Domain-Driven Design related support labels May 6, 2022
@odrotbohm odrotbohm self-assigned this May 6, 2022
@odrotbohm odrotbohm changed the title Better Kotlin support Add kMolecules DDD flavor of jMolecules DDD to work around issues in Kotlin May 6, 2022
@odrotbohm
Copy link
Member

That's in place now!

@odrotbohm
Copy link
Member

I've added a rudimentary Kotlin example project that shows the existing integration working.

@jntakpe
Copy link
Contributor Author

jntakpe commented May 9, 2022

Great thanks. All good for me

odrotbohm pushed a commit that referenced this issue May 16, 2022
The type-based flavor of the DDD building blocks uses methods that follow the Java Beans naming convention. Unfortunately, Kotlin currently does not implement these methods if properties are declared that match the convention [0]. This commit adds a kmolecules-ddd module that completely defines the same abstractions as jmolecules-ddd in Kotlin so that they can be properly used from Kotlin as well.

The types are located in the org.jmolecules.ddd package so that we can phase out this module as soon as that glitch in Kotlin is fixed and users can just drop this JAR here in favor of the jMolecules DDD one.

[0] https://youtrack.jetbrains.com/issue/KT-6653
odrotbohm added a commit that referenced this issue May 23, 2022
Kotlin modules need to use Dokka o generate the Javadoc JAR required to publish an artifact on Maven Central. We're now generating that during the release build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: ddd Domain-Driven Design related support type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants