Last active
July 30, 2025 07:24
-
-
Save trikitrok/eb6e5ed25ccdea2421565b6981ca488e to your computer and use it in GitHub Desktop.
ClaimBuilder using CRTP abbreviated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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