Builder
public class Person
{
public string Name {get;set;}
public int Age {get;set;}
public bool IsMale {get;set;}
public List<string> Skills {get; set;}
public Person()
{
Skills = new List<string>();
}
}public class PersonBuilder
{
private string _name;
private int _age;
private bool _isMale;
private List<string> _skills;
public PersonBuilder Create()
{
_name = string.Empty;
_age = 0;
_isMale = false;
_skills = new List<string>();
return this;
}
public PersonBuilder WithName(string name)
{
_name = name;
return this;
}
public PersonBuilder WithAge(int age)
{
_age = age;
return this;
}
public PersonBuilder IsMale(bool isMale)
{
_age = age;
return this;
}
public PersonBuilder AddSkill(string skill)
{
_skills.Add(skill);
return this;
}
public Person Build()
{
return new Person
{
Name = _name,
Age = _age,
IsMale = _isMale,
Skills = _skills
};
}
}Last updated