Junilu Lacar wrote:
Liutauras Vilda wrote:
I'd question ... do I need to stuff that to student class? Today documents are needed, tomorrow might not, and that changes based on to compliance rules defined by the university.
Junilu showed one way which would handle that better in my opinion.
My thoughts exactly. It's difficult to express the heuristics involved but I'll try anyway. I think the student.requiresDocuments() option isn't very attractive to me because it assigns the responsibility of enforcing the documentation requirements rule to the Student. However, the Student is also the subject of the rule. That's kind of like having students check and grade their own exam papers. I think my aversion for that option stems from the difference in the scope of responsibility I see a Student object has and the scope of responsibility that includes enforcing a rule like "An international student requires documents." It just feels like this should be the responsibility of something other than Student. That's why I hypothesized having some kind of Rule object to handle that responsibility might be a better choice. Again, this hypothesis needs to be explored and proven through experimentation (via unit testing).
Andy Rosemond wrote:I don't think I'm forcing the Student Object to enforce the rule. The way I wrote the code, I'm just tell the institution that "Yes I am an international student" nothing more. In reality, you as a Student will know this(probably have docs to prove it as well) The school decides to add it.
Liutauras Vilda wrote:
Andy Rosemond wrote:I don't think I'm forcing the Student Object to enforce the rule. The way I wrote the code, I'm just tell the institution that "Yes I am an international student" nothing more. In reality, you as a Student will know this(probably have docs to prove it as well) The school decides to add it.
You let student implement the definition what requires documentation and what's not and assigning this knowledge to himself (student). But does the student must know in which circumstances documentation is needed? Student just need to comply with whatever been defined already by somebody else. So it isn't student's knowledge. I mentioned before, if you are aware of something - doesn't mean you are responsible for.
This example is much more flexible. But Junilu is right, don't throw text there and there, write some tests, implement one way, see if it makes sense, implement another way,.. At some point you'll start seeing differences. Probably you need to go at least several times down the wrong route to see what issues it might cause to you.
Andy Rosemond wrote:How would this method look like without breaking encapsulation of the Student object?
Liutauras Vilda wrote:
Andy Rosemond wrote:How would this method look like without breaking encapsulation of the Student object?
Please explain how this breaks encapsulation?
Andy Rosemond wrote:I don't think I'm forcing the Student object to enforce the rule. The way I wrote the code, I'm just telling the institution that "Yes I'm an international student" nothing more. In reality, you as a Student will know this(probably have docs to prove it as well) The school decides to add it.
Andy Rosemond wrote:I though I broke encapsulation when I called the StudentType getter to make a decision.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |