CSSE 120 -- Intro. to Software Development

Homework 18

Due at the beginning of Session 19.

  1. Review chapters 1 through 12 of Zelle, giving greater emphasis to chapters 6 to 12, in preparation for Exam 2.
  2. You have no Angel quiz over the material for session 19.  Be prepared to do some serious project work in that session.
  3. Creating color buttons. This is an exercise on the object-oriented concepts of encapsulation, inheritance, and polymorphism. You are given a Button class that is able to create Button objects large enough to contain their labels.  Each Button can be enabled, disabled, and knows that it is clicked if it is enabled and a user uses the mouse to click it.  Your job is to design, implement, and test a ColorButton class that extends the Button class as described below.  Recall the checking account extension that you did in class when thinking about this problem.

    1. From your svn repository checkout the OOConcepts project if you have not done so already.  Study the Button class from the buttonWidget.py module to get an idea of the different components that make up a Button object.  Run the program in the colorButton.py module to see how it works.  You will be implementing and testing your ColorButton class in this module (colorButton.py).
    2. Complete the in-class exercises before you begin implementing your ColorButton class if you are still working on them. 
    3. In the colorButton.py module, replace <name> with your name, and <date> with the date you start working on this exercise.  Once you have done this part, commit your work to your repository.
    4. Remember, all of your implementation will be done in colorButton.py. Start designing and implementing the ColorButton class so that it extends (inherits from) the Button class.  Implement the constructor for ColorButton as follows. The parameters for the constructor should include one additional formal parameter, listOfColors, that you add at the end of the list of parameters .  listOfColors is a list of colors for the
      1. background of the button when it is enabled,
      2. outline of the button when it is enabled,
      3. background of the button when it is disabled, and
      4. outline of the button when it is disabled.

      The following was changed, 10/10/07: After calling the superclass's constructor (as the SavingsAccount constructor did in bankAccount.py), the constructor of ColorButton should initialize appropriately named instance variables to store these colors.

      Added 10/10/07: The constructor of ColorButton must call the superclass constructor to finish initialization. Because Button's constructor calls other methods, you'll need to initialize ColorButton's new instance fields before calling the constructor. So your ColorButton constructor should look like this:

      def __init__(self, win, label, center, listOfColors):
          # TODO: initialize additional instance fields of ColorButton
          Button.__init__(self, win, label, center)
      
    5. Implement function colorButtonTest() to test what you have done so far.  colorButtonTest() should generate at least 3 ColorButton objects with different color lists and allow users to click them, as the buttonTest() function does. Comment out the "buttonTest(window, text)" line in function main() and invoke the colorButtonTest() function. Run your program and notice the behavior.  You should not see any change in behavior between the color buttons you created and the buttons that were created by buttonTest().  Why?  Once you are certain that your implementation works, commit your work to your repository.
    6. Now add new versions of the enable( ), and disable( ) methods that appropriately change the color of a ColorButton object when it is enabled or disabled. Use the same signature for these methods as those used in the Button class.

      Add code to the  colorButtonTest() function to test the enable() and disable() methods. The code that you add can be similar to the code in the buttonTest() function.

      Run your program and notice the behavior. When the color buttons are enabled or disabled the colors should change according to the description in part d. above. Do you see why? 

      Added 10/10/07: You'll probably also notice that the label of the button is now hidden behind the rectangle. This is due to a "bug" in our implementation of Button. When we designed button we didn't anticipate adding a subclass that would color the rectangle. We assumed the rectangle would remain unfilled, so we could safely draw the button text first, then draw the rectangle on top. To correct this problem please swap lines 38 and 39 of buttonWidget.py. This is the only change you should make to that file.

      Once you are certain that your implementation works, commit your work to your repository.

    7. Complete the assignment by replacing <this_way> in the initial comments with a description of how ColorButton extends Button. Commit the final version of your code to your repository.
  4. Project work: Try to make some progress on your Quixo team project.  Take note of your milestone for session 20. By then your program should  be able to show the game state for any given state of the game.

  5. Polymorphism: The object-oriented concept known as polymorphism is not unique to Python.  It's use is prevalent in most programming languages that support object-oriented development.  Here is a description of the concept of polymorphism; note that the first example is written in Python!