Skip to content

Refactor: Replace operator invoke with execute in use case classes#2

Open
Dev-Pasaka wants to merge 2 commits intoantonarhipov:mainfrom
Dev-Pasaka:usecases
Open

Refactor: Replace operator invoke with execute in use case classes#2
Dev-Pasaka wants to merge 2 commits intoantonarhipov:mainfrom
Dev-Pasaka:usecases

Conversation

@Dev-Pasaka
Copy link

This PR refactors all use case classes to replace operator fun invoke(...) with a standard execute(...) function.

  • Avoids promoting operator overloading without clear benefit, as suggested in the review.
  • Updates service classes to explicitly call .execute(...) for clarity.
  • While invoke() can simplify code when use cases are injected, in this structure explicit methods are clearer and more beginner-friendly.

Thanks for the earlier feedback — this should align better with clean DDD examples.

Dev-Pasaka added 2 commits May 4, 2025 17:34
- Replaced all  declarations with
- Updated service classes to call  instead of
- Aligns with review recommendation to avoid unnecessary operator overloading
- Improves readability and avoids promoting patterns without clear necessity
@Dev-Pasaka
Copy link
Author

Thanks again for the feedback!

In addition to the recent refactor replacing operator fun invoke with explicit execute(...) methods in the use cases, I'm planning to introduce independent unit tests for each use case.

This approach will help ensure that each use case behaves as expected in isolation, facilitating early detection of issues and making future refactoring safer and more manageable.

Looking forward to your thoughts on this direction!

operator fun invoke(customerId: CustomerId, noteId: Long?, remindAt: LocalDateTime, message: String):Reminder{
fun execute(customerId: CustomerId, noteId: Long?, remindAt: LocalDateTime, message: String): Reminder {
val reminder = Reminder(
id = ReminderId(value = (1000_000_000..1_899_999_999_999).random()),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being picky. I think the ID should be generated by the Repository implementation. In real life it would be the sequence in the database, of course, or there should be a generator that keeps track of the values. The random number, even though the probability here is negligible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants