Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active July 30, 2025 07:24
Show Gist options
  • Save trikitrok/eb6e5ed25ccdea2421565b6981ca488e to your computer and use it in GitHub Desktop.
Save trikitrok/eb6e5ed25ccdea2421565b6981ca488e to your computer and use it in GitHub Desktop.
ClaimBuilder using CRTP abbreviated
// imports elided...
public abstract class ClaimBuilder<T extends ClaimBuilder<T>> {
// some fields elided...
protected ClaimBuilder() {
// setting some defaults elided...
}
public T withClaimId(String number) {
this.claimId = claimId(number);
return self();
}
public T withCompanyId(String id) {
this.companyId = CompaniesFactory.companyId(id);
return self();
}
public T describedAs(String description) {
this.description = description;
return self();
}
// other common setters elided
protected ClaimData buildData() {
return new ClaimData(
claimId,
companyId,
description,
claimDate,
policyNumber,
status
);
}
@SuppressWarnings("unchecked")
protected final T self() {
return (T) this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment