mercredi 30 mai 2018

What purpose of this code pattern?

I am debugging somebody code and I just don't understand whats the benefit of coding this way in Java

I am no Java Design Pattern expert but I would like to know when is this applicable?

public class MyClass {

    public static class Builder {
        //Getters and setters
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public MyClass(Builder builder) {
        //More Methods
    }

    public static void main(String[] args) {
        MyClass.Builder builder = MyClass.newBuilder();
        new MyClass(builder);
    }
}

Aucun commentaire:

Enregistrer un commentaire