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
Grade
object knows what its letter string stands for, whether it should count for credit etc. - A
GradeReader
object knows how to create suchGrade
from lines in a file. - A
Summary
object 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.