cs445, Spring 2016 - HW-2


Part (i) - 30%

Create a project called TableLamp. The TableLamp has a Button and a Lightbulb.

The Lighbulb responds to on() and off() messages. When turned on the light bulb will print to stdout "Lightbulb on". When turned off the light bulb will print to stdout "Lightbulb off."

In a future homework we'll work with more sophisticated light bulbs, such as dimmable and colored.

The Button knows how to respond to switchOn() and switchOff(). Later in this homework we'll work with a different type of button.

When switched on the Button will print "Button switched to ON" to stdout. WHen switched off the button will print "Button switched to OFF" to stdout.

In the simplest implementation of a TableLamp the Button will have a Lightbulb.

Write a Main class that creates a Button and then commands it to switch on and off.

Part (ii) - 30%

If you din't create the Lightbulb and the Button in separate packages, then now it's time to do it.

We'll want them separate because the we want to be able to change the Button without having to rebuild the Lightbulb and we want to be able to change the Lightbuld without having to re-build the BUtton.

Decouple the Button and the Lightbulb through Dependency Inversion.

Write a Main class that creates a table lamp and then commands it to switch on and off.

Part (iii) - 40%

Replace the Button with a PushdownButton, one that switches between on and off every time it's pushed. Hint: this button takes a "PushButton()" message.

NOTE: this the same type of "button" - called a pull chain switch - you've seen in table lamps and such, like the one in the image to the left of this text.

Did you need to re-build the Lightbulb when you replaced the button?

Varia

Follow the Assignment Submission instructions in the syllabus to submit your work. Don't forget that we'll also have a look at your code repository, make sure you've shared it with us and that you also include instructions for how to check out your code from the command line and how to build it.

Don't forget the check out the syllabus for the test environment of your work and what's needed in terms of automated unit testing.


Last update: Feb 23, 2016 Virgil Bistriceanu cs445 Computer Science

$Id: HW-2.html,v 1.1 2016/02/23 23:48:53 virgil Exp $