Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Last active May 2, 2017 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicFinn/30ef831d8b8225737fb2a6ebde5dbe27 to your computer and use it in GitHub Desktop.
Save DominicFinn/30ef831d8b8225737fb2a6ebde5dbe27 to your computer and use it in GitHub Desktop.
Classes for my blog post on Object Creation.
sealed class GoodDojo
{
private readonly IList<Student> students;
public Sensei Sensei { get; }
public IEnumerable<Student> Students => this.students;
public GoodDojo(Sensei sensei)
{
Sensei = sensei;
this.students = new List<Student>();
}
public GoodDojo(Sensei sensei, IEnumerable<Student> students)
{
Sensei = sensei;
this.students = students.ToList();
}
public string Summary => $"this dojo is run by {Sensei.Name} and has {Students.Count()} students";
public void AddNewStudent(Student student)
{
// business logic? validation? checks?
this.students.Add(student);
}
}
class Program
{
static void Main(string[] args)
{
var goodDojo = new GoodDojo(new Sensei("Dom"));
Console.WriteLine(goodDojo.Summary);
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment