I want to store sorted instances of Student class, into Students class. And I am using staticmethod in Students class for sorting. I could be wrong, but the design seems a bit ugly and want to avoid using static method (the most ideal way in my mind is using a class method in class Student which returns student ID, and use this method for sorting, but it seems not an easier way to set a class method of class Student in class Students for sorting), if there is a better design, appreciate if you could share,
class Student:
def __init__(self, id):
self.id = id
class Students:
def __init__(self, students):
self.sortedStudents = sorted(students, key=Students.getStudentID)
@staticmethod
def getStudentID(student):
return student.id
def dumpAllStudents(self):
for student in self.sortedStudents:
print student.id
students = []
students.append(Student(100))
students.append(Student(90))
students.append(Student(80))
allStudents = Students(students)
allStudents.dumpAllStudents()
thanks in advance, Lin