[Tutor] designing POOP
kent37 at tds.net
Thu Feb 7 22:07:02 CET 2008
> The TDD method is the method used in my tutorial:
> Python Programming for the Absolute Beginner 2E. Michael Dawson. 2006.
> Dawson uses a very simple Tamagotchi example called Critter Caretaker
> to introduce the mechanics of POOP. However, perhaps he is using
> the TDD method of "design"?
I don't think Dawson uses TDD. AFAIK he doesn't talk about unit-testing
at all, which is the fundamental practice of TDD. For an example of unit
tests in Python, see
> here is
> a first little testing snippet from the testing directory, using the TDD
> method. I'm confident that if I am using the terminology incorrectly,
> someone will point out the error of my ways.
I think you are using the terminology incorrectly. I would call this an
example of experimental programming, maybe. A classic example of TDD in
Java is here:
> class TestClass1(object):
> """ please give me a better name"""
> def __init__(self):
> """please document me"""
> self.name = ""
> self.answer = ""
> self.strength = 20
> self.wealth = 45
> self.light = 0
> self.tally = 0
This is a good example of a data class - a class that is just a
container for data. That is a code smell. It seems to contain unrelated
values - name and strength are attributes of the player, light is an
attribute of the environment. So it should probably be more than one
class, or, since the entire program is in one loop, these could just be
local variables of main().
> def main():
> tc1 = TestClass1() # instance
> tc1.__init__() # invoke method
The __init__() method is called implicitly by calling TestClass1().
Generally the only time you explicitly call __init__() is when calling
the method of a base class.
More information about the Tutor