First, just as a suggestion to make it easier to understand your model, I suggest you call your "Discipline" class. Calling "Class" is confusing because all of them are classes (in terms of OO) and "Matter" are actually the subjects covered in a discipline.
Evaluating the scenarios you've proposed:
1) If you use a list of Disciplines as an attribute of the Student class, you delegate to the Student class any changes to your Disciplines. In this case, you would be applying the Encapsulation concept, meaning that the responsibility for knowing the implementation details would be hidden in the Student class.
Please answer the following questions to see if the above approach suits your use case:
-
What are the business rules applicable to the use case? For example, is there a minimum / maximum number of students per subject, or a minimum / maximum number of subjects per student?
-
There are disciplines that have others as predecessors, and it is necessary to consult if that Student has already taken all the predecessors before enrolling him?
In these examples, Student methods would be responsible for this control, regardless of whether another class is changing the disciplines for that student.
So remember that objects have data (attributes) and behavior (methods), the latter being the main difference between objects and simple data structures.
A model in which domain classes only store their attributes and references to each other and all processes occur outside of these classes is an anti-pattern known as Anemic Domain Model .
So it's no use just hiding the list of disciplines within the Student class and building several other classes to handle the changes to this list, since you would be breaking the encapsulation.
With respect to performance, it is up to you to decide, at any given moment, whether to construct a Student object with all the Disciplines ( Eager Fetch ), or only with the basic data of the Student > Lazy Load ). In fact, I can not imagine an educational institution where the number of active students and disciplines is so great as to impact the performance of the application. If you are slow, it will probably be for another reason, such as unoptimized code, server configuration error, undersized hardware etc.
2) If you use a data structure, such as a TreeMap, relating lists of Students to each Discipline object, you may see that TreeMap being passed as a parameter from side to side in several methods. All of these methods would have to implement the existing controls in the relationship between these two objects, or worse, it would take a third class, Student and Discipline Specialist, just for that.
As one of your concerns is with security, how do you ensure that all parts of the code that use this TreeMap will obey all the rules?
What class would be the responsibility of comparing the data of this TreeMap with other data, for example another TreeMap with the predecessor disciplines already studied by a Student?
One criterion that can also help you make this kind of design decision is to see if the proposed implementation makes sense in the real world .
-
It makes sense for a student to know how many subjects he or she should enroll in? Or know that you can not enroll in more than X disciplines?
-
Does it make sense for a student to know how to answer which subjects he / she studies?
-
Does it make sense for a student to ask to leave a discipline?
19.03.2018 / 19:46