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

Sheila King sheila@thinkspot.net
Sat, 24 Mar 2001 11:49:41 -0800


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

:Hey everyone,
:
:I'm back working on a little Python program, trying to scratch a specific
:itch that I keep having with my students at school. Specifically, I often
:want to put my students in small groups to work on class work, labs, or
:whatever we're working on that day. It's too time consuming to go through a
:big process every day and I want to rearrange the groups often. I thought a
:small computer program would be just the ticket.

FYI: I use a deck of cards. If I have 24 students present, and I want groups
of four, I choose all the cards Ace through six, shuffle them, and go around
having the students each draw one card. Then everyone who drew an Ace forms
one group, all the twos form another group, and so on. If I want them in
pairs, then the two red Aces are a pair, and the two black Aces are a pair,
and so on. Obviously, this doesn't ensure gender mixing and so on. And I like
the idea of your little program very much. Heh, if you get it working, I
wouldn't mind a copy, myself.

:To keep things simple for now, I'm storing the students in a simple text
:file with last name, first name, and gender. (At some point I'd like to have
:the option of mixing gender in the groups.) Here's a sample file:
:
:van Rossum,Guido,M
:Boop,Betty,F
:Gauld,Alan,M
:Flintstone,Wilma,F
:Rubble,Betty,F
:Yoo,Danny,M
:Wilson,Tim,M
:Crawford,Cindy,F
:Van Laningham,Ivan,M
:Lutz,Mark,M
:Ascher,David,M
:Watters,Aaron,M
:
:I'd like to try a OOP approach, but one of the things I struggle with is the
:initial design stage. I've asked about this before and I've done some
:reading, but I still haven't found a way of thinking about problems like
:this that make a lot of sense to me.
:
:My program, it would seem, would logically have classes the correspond to
:individual students, groups, and perhaps the class as a whole. Here's what
:I've come up with so far:
:
:class Student:
:	def __init__(self, ln, fn, gender):
:		self.ln = ln
:		self.fn = fn
:		self.gender = gender
:		
:class Group:
:	def __init__(self, studentList):
:		self.studentList = studentList
:	def display(studentList):
:		pass
:
:class Roster:
:	def __init__(self):
:		pass
:	def loadFile(self, filename):
:		import string
:		classList = []
:		f = open(filename, 'r')
...<snipped>...
(BTW, I give you permission to add me to the list ;)
We sure have a dearth of female types on these programming lists, don't we?)

:I'd love to hear some advice from others on the list. What design advice can
:you give? Any other suggestions?

Heh, I'll wait and see what some of the "experts" suggest. Right now I'm
working on some cgi scripts.

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