Created
July 6, 2019 14:59
-
-
Save bayraktugrul/904ffe8c3b2fb1238cd47cae5646fa51 to your computer and use it in GitHub Desktop.
class with builder pattern
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
public class Person { | |
private String name, surname, address; | |
public Person(Builder builder) { | |
this.name = builder.name; | |
this.surname = builder.surname; | |
this.address = builder.address; | |
} | |
public String getName() { | |
return name; | |
} | |
public String getSurname() { | |
return surname; | |
} | |
public String getAddress() { | |
return address; | |
} | |
public static class Builder{ | |
private String name, surname, address; | |
public Builder(){ } | |
public Builder name(String name){ | |
this.name = name; | |
return this; | |
} | |
public Builder surname(String surname){ | |
this.surname = surname; | |
return this; | |
} | |
public Builder address(String address){ | |
this.address = address; | |
return this; | |
} | |
public Company build(){ | |
return new Company(this); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment