Bu sadece bir deneme
-
-
Save farukcan/7dd58b9b0c126b73abeb0b498c263c49 to your computer and use it in GitHub Desktop.
Builder Pattern Sample
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
// Person person = new Person.Builder().name("Name").surname("Surname").address("Address").build(); | |
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