[Tutor] Design Question

David Hamilton dsh0105 at comcast.net
Sat Jun 2 13:56:26 CEST 2007


Thanks for the guidance!  I'm glad to know my design wasn't wildly 
off-base. I will most likely take your advice about using pickle to 
implement persistence.  As for old style vs new style constructors...I'm 
still a little fuzzy on the details, but I've done enough reading to see 
that new style is vastly improved. I'll keep working on that.

Thanks again,

David

Brian van den Broek wrote:
> dsh0105 at comcast.net said unto the world upon 06/01/2007 10:46 AM:
>> I think I may have sent an incomplete version of this question a 
>> moment ago (sorry). Here is the complete question:
>>
>> I'm designing something along the lines of a flash card program. It's 
>> mostly just an exercise in learning Python, but I'd like it to be at 
>> least marginally usable when I'm done. So I'm looking for 
>> comments/suggestions on the key pieces of the design: the questions 
>> and the flash card deck:
>> Psudo-code of current design:
>>
>> class Deck():
>>     """Provides managment and informational functions about a set of 
>> questions to be asked
>>         methods incldue:
>>         __init__(questions) -- takes a list of question and creates a 
>> new deck with these questions.
>>         add_question(self,question) -- Adds a question to the current 
>> deck
>>         remove_question(self,question) -- returns True if the 
>> question was removed, False otherwise
>>         get_question() -- Returns the next unanswered question in the 
>> deck
>>         get_stats() -- returns a tuple containing: number_asked, 
>> number_correct, number_remaining
>>                 shuffle_deck() -- shuffles the order of the remaining 
>> questions.
>>         Deck Overrived the __len__ function so that the len returned 
>> is the number of questions in the deck."
>>        
>>
>> class Question():
>>     """Provides questions to be asked
>>     methods:
>>     __init__(self,question,answer) -- question string representing 
>> the question.                                     answer can be a 
>> text string, a tupple (for multiple correct answers)
>>                                     or an object implementing an 
>> is_correct() method that returns a boolean
>>                                    
>>     check_answer(self,answer) -- tests to see if the answer is 
>> correct and returns a boolean     """
>>                                    
>>                                    
>> Mostly I'm wondering, is this over-kill? The idea is to allow for the 
>> deck to be used for as wide a variety of purposes as possible. Also, 
>> I want to make it easy to write code that generates decks.  Is this 
>> design over-kill?
>>
>> Any comments/suggestions welcome.
>>
>> Thanks,
>>
>> David
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> David,
>
> I'd make Deck and Question subclass object so as to have new-style 
> classes, as in:
>
> class Deck(object):
>     # code here
>
> If you don't know about the difference between classic classes and 
> new-style, you needn't worry about it for now. There are a number of 
> ways in which new-style are better, though.
>
> I also have a suggestion that you might want to think about after you 
> get the basic functionality working. When I did something similar, I 
> used the pickle module make my Questions persistent between sessions, 
> and had each Question keep track of how many times it has been asked 
> and correctly answered. I then had my Deck.get_question pick which 
> Question to ask in a way that favoured both Questions that had been 
> rarely asked, and those that had the highest error rates.
>
> Best,
>
> Brian vdB
>



More information about the Tutor mailing list