'''lecture_29_colbystudent.py
Design class ColbyStudent
Oliver W. Layton
CS 151: Computational Thinking: Visual Media
Fall 2020

TODO:
1. Add last day of class global variable (Dec 4)
    - Access with vs. without get method
    - Change date to Nov 24 and demonstrate change across all ColbyStudent objects
    - Show symbol table
2. Shallow copy access for getGrades in main code
    - Show symbol table
    - Fix issue in getGrades
'''


class ColbyStudent:
    lastDayOfClass = 'Dec 4'

    def __init__(self, name, year=2022):
        # Initialization data
        self.name = name
        self.year = year

        # Derived data
        self.grades = []
        self.gpa = 0.0

    def getName(self):
        return self.name

    def getGrades(self):
        # return self.grades  # shallow copy / nickname
        return self.grades[:]  # deep copy by independence rule for slicing lists

    def addGrade(self, newGrade):
        self.grades.append(newGrade)

    def getLastDay(self):
        return ColbyStudent.lastDayOfClass


'''
Update 1: class global variable
'''
mike = ColbyStudent('Mike', year=2022)
lilly = ColbyStudent('Lilly', year=2022)
print('Mike last day:', mike.getLastDay())
print('Lilly last day:', lilly.getLastDay())

print("Class access last day:", ColbyStudent.lastDayOfClass)

ColbyStudent.lastDayOfClass = 'Nov 24'
print('Mike last day:', mike.getLastDay())
print('Lilly last day:', lilly.getLastDay())

'''
Update 2: Copy issues
'''
# Make a student, add grades to show memory access problems
# mike = ColbyStudent('Mike', year=2022)
# mike.addGrade(4)
# mike.addGrade(3)
# mike.addGrade(1)

# mikesGrades = mike.getGrades()
# print('Mike\'s grades outside the object', mikesGrades)

# # Modify grades then print grades and the grades from the student accessed again
# mikesGrades.pop()
# print('Mike\'s grades outside the object (after pop)', mikesGrades)
# print('Mike\'s grades object instance variable', mike.getGrades())

# Distilled basic idea:
# gradesList = [1, 2, 3]
# copy = gradesList[:]
# gradesList.pop()
# print('Orig', gradesList)
# print('Copy', copy)
