Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Move validation outside of the entity itself.</p> </blockquote> <p>One instructor shouldn't know about all other instructors. Validation against set of instructors isn't responsibility of one particular instructor.</p> <blockquote> <p>Allow for access to a instructor repository from necessary entities that are attempting to perform this validation.</p> </blockquote> <p>Domain model should be persistence ignorant. Need to break that indicates flaws in Your model.</p> <blockquote> <p>Create a service that allows access to a list of instructors by instrument category.</p> </blockquote> <p>This bit of information reveals lack of aggregate root - I would call it <code>InstrumentClass</code>. </p> <p>Introducing that into Your model would solve some of Your issues. <code>InstrumentClass</code> would hold available instructors that teaches particular instrument.</p> <p>Next thing You need to figure out is how to describe properly student that is assigned to class. Unfortunately I can't name it at the moment (maybe <code>Participation</code>?). But that entity would be used for <code>InstrumentClass</code> to figure out which instructors are too busy.</p> <hr> <p>Here's my "free-style" (just to show what I see) on modeling Your domain:</p> <pre><code>using System; public class Main{ public Main(){ var instructor = new Instructor(); var instrument = new Instrument("saxaphone"); var saxaphoneClass = new InstrumentClass(saxaphone,teacher); var me=new Person("Arnis"); //here, from UI, I can see available classes, choose one //and choose according instructor who's assigned to it var request=me.RequestEnrollment(saxaphoneClass, instructor); saxaphoneClass.EnrollStudent(request); } } public class Person{ public IList&lt;EnrollmentRequest&gt; EnrollmentRequests { get; private set; } public EnrollmentRequest RequestEnrollment (InstrumentClass instrumentClass,Instructor instructor){ if (!instrumentClass.IsTeachedByInstructor(instructor)) throw new Exception("Instructor does not teach this music instrument"); var request=new EnrollmentRequest(this,instrumentClass,instructor); EnrollmentRequests.Add(request); return request; } } public class EnrollmentRequest{ public Person Person{ get; private set; } public InstrumentClass InstrumentClass { get; private set; } public Instructor Instructor{ get; private set; } } public class InstrumentClass{ public void EnrollStudent(EnrollmentRequest request){ var instructor=request.Instructor; var student=new Student(request.Person); var studies=new Studies(this,student,instructor); //TODO: this directiveness isn't good //student/instructor should listen for class events themselves //and class should listen if by any reason instructor or student cannot //participate in studies student.EnrollInClass(studies); instructor.AssignStudent(studies); Studies.Add(studies); } public bool IsTeachedByInstructor(Instructor instructor){ return Instructors.Contains(instructor); } public InstrumentClass (Instrument instrument, params Instructor[] instructors){ Instrument=instrument; Instructors=instructors.ToList(); } public IList&lt;Instructor&gt; Instructors{get;private set;} public IList&lt;Studies&gt; Studies { get; private set; } public Instrument Instrument { get; private set; } } public class Studies{ public Student Student { get; private set; } public Instructor Instructor { get; private set; } public InstrumentClass InstrumentClass { get; private set; } } public class Student{ } public class Instructor{ } public class Instrument{ } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload