Remove the "Loopyness" from Lobby/Rooms/User
This example uses Student and School to try to keep the conversation generic.
Wanted to dump my thoughts before I forget by next session.
using System;
using System.Collections.Generic;
class Student // User
{
public string Name { get; set; }
public School School { get; set; }
}
class School // Room
{
public string Name { get; set; }
public List<Student> Students { get; } = new List<Student>();
public void AddStudent(Student student)
{
if (student.School != null)
{
Console.WriteLine($"{student.Name} already belongs to {student.School.Name}. Cannot add to {this.Name}.");
return;
}
Students.Add(student);
student.School = this;
}
public void RemoveStudent(Student student)
{
if (!Students.Contains(student))
{
Console.WriteLine($"{student.Name} does not belong to {this.Name}. Cannot remove");
return;
}
Students.Remove(student);
student.School = null;
}
public List<Student> GetStudents()
{
return Students;
}
}
class Program
{
static void Main()
{
// Creating schools and students
School school1 = new School { Name = "School 1" };
School school2 = new School { Name = "School 2" };
Student student1 = new Student { Name = "Alice" };
// Adding students to schools
school1.AddStudent(student1);
school1.AddStudent(student1); // Attempting to add the same student to the same school again
}
}
Remove the "Loopyness" from Lobby/Rooms/User
This example uses Student and School to try to keep the conversation generic.
Wanted to dump my thoughts before I forget by next session.