Guest User

Untitled

a guest
Sep 12th, 2012
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. public class PersonBuilder {
  2.  
  3.     public static FirstNameStep newBuilder() {
  4.         return new Steps();
  5.     }
  6.    
  7.     private PersonBuilder() {
  8.     }
  9.    
  10.     public static interface FirstNameStep {
  11.         LastNameStep firstName(String string);
  12.     }
  13.    
  14.     public static interface LastNameStep {
  15.         RemainingSteps lastName(String value);
  16.     }
  17.  
  18.     public static interface RemainingSteps {
  19.  
  20.         Person build();
  21.         RemainingSteps dateOfBirth(Date date);
  22.        
  23.     }
  24.    
  25.     private static class Steps implements FirstNameStep, LastNameStep, RemainingSteps {
  26.         private String firstName;
  27.         private String lastName;
  28.         private Date dateOfBirth;
  29.    
  30.         public LastNameStep firstName(String value) {
  31.             this.firstName = value;
  32.             return this;
  33.         }
  34.    
  35.         public RemainingSteps lastName(String value) {
  36.             this.lastName = value;
  37.             return this;
  38.         }
  39.    
  40.         public RemainingSteps dateOfBirth(Date value) {
  41.             this.dateOfBirth = value;
  42.             return this;
  43.         }
  44.    
  45.         public Person build() {
  46.             return new Person(firstName, lastName, dateOfBirth);
  47.         }
  48.    
  49.     }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment