Advertisement
bero_0401

Builder Pattern

Oct 3rd, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace revision
  8. {
  9.     internal class PersonBuilder
  10.     {
  11.         private int _id;
  12.         private string _name;
  13.         private string _phone_Number;
  14.         private string _address;
  15.         private DateTime _birthDate;
  16.  
  17.         public PersonBuilder SetId(int id) { this._id = id; return this; }
  18.  
  19.         public PersonBuilder SetName(string name) { this._name = name; return this; }
  20.  
  21.         public PersonBuilder SetPhoneNumber(string phoneNumber) { this._phone_Number = phoneNumber; return this; }
  22.  
  23.         public PersonBuilder SetAddress(string address) { this._address = address; return this; }
  24.  
  25.         public PersonBuilder SetBirthDate(DateTime birthDate) { this._birthDate = birthDate; return this; }
  26.  
  27.  
  28.         // we postpone the intialization
  29.         public Person Builder()
  30.         {
  31.             return new Person(_id , _name , _phone_Number , _address , _birthDate);
  32.         }
  33.  
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement