Last active
May 2, 2017 19:39
-
-
Save DominicFinn/30ef831d8b8225737fb2a6ebde5dbe27 to your computer and use it in GitHub Desktop.
Classes for my blog post on Object Creation.
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
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); | |
} | |
} |
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
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