Skip to content

dddpaul/java-builders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

java-builders

Examine Java objects build variants.

Telescopic constructor

Telescopic constructor NutritionFacts.java example.

Pros:

  • simple.

Cons:

  • poor scalability.

JavaBeans

JavaBeans NutritionFacts.java example.

Pros:

  • simple;
  • scales well.

Cons:

  • too much boilerplate in usage;
  • inconsistency and mutability are permitted.

Builder

Builder NutritionFacts.java example.

Pros:

  • simple usage;
  • built instances are immutable and consistent.

Cons:

  • too much boilerplate in class definition.

Elegant builder

Elegant builder NutritionFacts.java example.

Pros:

  • class definition is shorter than in classic builder pattern.

Cons:

IDEA InnerBuilder

IDEA InnerBuilder NutritionFacts.java example.

Pros:

  • fields only have to be specified, all of the methods can be generated by IDEA.

Cons:

  • you have to use IDEA plugin;
  • all of the boilerplate resides in source control system still.

Google AutoValue

Google AutoValue NutritionFacts.java example.

Pros:

  • much more less boilerplate;
  • automatic equals(), hasCode() and toString() methods generation.

Cons:

  • it's a code generation nevertheless, so it requires something like "mvn compile" before using
  • builder support is experimental (you must use latest version from GitHub).

Project Lombok Builder

Project Lombok Builder NutritionFacts.java example.

Pros:

  • shortest declaration.

Cons:

POJO Builder

POJO Builder NutritionFacts.java example.

Pros:

  • can be used in conjunction with AutoValue or Lombok;
  • is recommended by Umputun :)

Cons:

  • can't generate getters and setters;
  • it's a code generation nevertheless, so it requires something like "mvn compile" before using.

Immutables

Immutables NutritionFacts.java example.

Pros:

  • boilerplate is gone completely;
  • automatic equals(), hasCode() and toString() methods generation;
  • automatic withXXX() methods generation;
  • uses Java 8 features (Optional etc.)

Cons:

  • it's a code generation nevertheless, so it requires something like "mvn compile" before using.

Links

About

Examine Java objects build variants

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages