mercredi 14 mars 2018

How would you decouple a scenario of lessons and students?

Assume you are making a software that manages classes and students.

I'd assume you would have an administrator class, lesson class, and student class.

The administrator class can have various functions such as "get the list of all available lessons" or "get the list of all lessons that a student is enrolled in".

Here's the tricky part.

A lesson can have many students while a student can have many lessons.

Here are some implementations I have thought of:

  1. Lesson class contains list of students and student class contains list of lessons:

    Pro: Straightforward, Con: Coupled

  2. Lesson class contains list of students and in order to do "get all lessons a student is enrolled in" the administrator class would first get all lessons and then filter lessons containing that student.

    Pro: Not coupled, Con: Inefficient computing

  3. In the administrator class, have the following fields :

    • HashMap<Lesson, [Student]>
    • HashMap<Student, [Lesson]>

    Pro: Not coupled, Con: Messy

None of them seem satisfying to me. Can I get some feedback on this dilemma? What is the typically accepted design pattern?

Aucun commentaire:

Enregistrer un commentaire