[Tutor] OOP design (w/ example :-)

Sheila King sheila@thinkspot.net
Sat, 24 Mar 2001 14:46:47 -0800


I had been thinking a bit about this.

Why not have classes:
Student, Group and Class

And Class is a class that has a Roster, which is a dictionary of Students. And
it also has a GroupList, which is a dictionary of all the groups in the class.

And each student has a field, that is a Group, which has a value of the group
identifier that the student is assigned to. Otherwise, it has a value of None.
And each group has a field, MaxNumber, which is the maximum number of students
that you want in a group.

Then, you could load your data file into the Roster of the Class. Then class
could have a method that assigns groups. Make a temporary copy of the Roster
dictionary. Then randomly select students from it, to assign to groups. When a
student is selected, remove them from the temporary dictionary, so that the
student cannot be selected again (so you don't have to check for dupe
selections).

Hm..just thinking out loud. I'm still interested to see suggestions from the
experts on this problem.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/

On Sat, 24 Mar 2001 16:27:46 -0600 (CST), Timothy Wilson <wilson@visi.com>
wrote about Re: [Tutor] OOP design (w/ example :-):

:Here's what I think is an improved version of my program. I'm able to create
:a roster of student objects. (See interpretor session below.) What to do
:next?
:
:class Student:
:	def __init__(self, ln, fn, gender):
:		self.ln = ln
:		self.fn = fn
:		self.gender = gender
:		
:class Group:
:	def __init__(self, groupList):
:		self.groupList = groupList
:	def display(groupList):
:		for i in groupList:
:			print "%s, %s" % (self.ln, self.fn)
:
:class Roster:
:	def __init__(self, studentList):
:		self.studentList = studentList
...<snipped>...