Section 7.6 OOP Summary
Notice that we took a single method, the
processGrades method, that was somewhat complex, and implemented the same functionality by having three different classes, and objects of those classes, collaborate together:-
A
Gradeobject knows what its letter string stands for, whether it should count for credit etc. -
A
GradeReaderobject knows how to create suchGradefrom lines in a file. -
A
Summaryobject knows how to keep track of totals for a list of grades given to it by theGradeReader.
It is more lines of code, but broken down in more digestible parts, and with clear understanding of what each part does: If we want to change the file format, weโll need to adjust the work done the
GradeReader class; if we want to change the grade options weโll mess with the Grade class, if we want to change the tallies we generate weโll do something in the Summary class. We have used the Single Responsibility Principle to guide us in this process, and along the way saw a number of refactorings that can help us address different situations.
