zendesk-java-client icon indicating copy to clipboard operation
zendesk-java-client copied to clipboard

Add builder API to entities

Open internetstaff opened this issue 1 year ago • 5 comments

Any chance of adding e.g. lombok @Builders for entities?

internetstaff avatar Jun 12 '24 16:06 internetstaff

Sorry, I'd rather not add lombok to this project. Feel free to provide a PR with builders though.

PierreBtz avatar Jun 18 '24 16:06 PierreBtz

I can understand your lombok hesitancy, having gone through that myself many years ago.

I'm concerned, however, that otherwise builders will add a large amount of clutter to the model classes.

Do you have an idea of what you'd want that to look like?

internetstaff avatar Jun 19 '24 13:06 internetstaff

I'm concerned, however, that otherwise builders will add a large amount of clutter to the model classes.

I agree. I've had my eyes for some months on https://github.com/jonas-grgt/bob that look like a promising alternative to lombok. It's still a bit young but promising. I'll try experimenting a bit with it see if we could maybe introduce it in this project.

PierreBtz avatar Jun 24 '24 09:06 PierreBtz

Mhh, this dependency wouldn't fit the bill right now, it doesn't handle inheritance well (not surprised, it's also often an issue with Lombok anyway...).

Rewinding a bit here, what's the motivation for using builders? Is it to have a less verbose/more compact code when you instanciate entities? In which case, would fluent setter be enough, ie instead of writing something like:

  private Ticket createSampleTicket() {
    Ticket ticket = new Ticket();
    ticket.setId(Math.abs(RANDOM.nextLong()));
    ticket.setComment(new Comment(TICKET_COMMENT1));
    ticket.setUpdatedAt(NOW);
    ticket.setCustomStatusId(Math.abs(RANDOM.nextLong()));
    return ticket;
  }

you'd write:

   private Ticket createSampleTicket() {
    return new Ticket()
            .setId(Math.abs(RANDOM.nextLong()))
            .setComment(new Comment(TICKET_COMMENT1))
            .setUpdatedAt(NOW)
            .setCustomStatusId(Math.abs(RANDOM.nextLong()));
  }

PierreBtz avatar Jun 24 '24 10:06 PierreBtz

Fluent setters would be an improvement, but tbh I seem to rarely see that as a pattern anymore relative to builders. :shrug:

internetstaff avatar Jul 01 '24 12:07 internetstaff

This issue/PR is stale because it has been opened 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Aug 31 '24 08:08 github-actions[bot]