mardi 23 août 2022

Simple Java Builder Pattern Multiple Classes

Imagine we have 2 classes like this

class Foo{
   private Bar bar;

   ....
}

class Bar{
   ....
}

If we use Builder pattern for this, FooBuilder should have a Bar field or a BarBuilder field?

In the second case

//Constructor in Foo
public Foo(FooBuilder builder){
  ...
  this.setBar(builder.barBuilder.build());
}

Aucun commentaire:

Enregistrer un commentaire