COMP204 Homework 11
FlyweightCommand.java
CommandPasser.java
ButtonListener.class
CommandPasser$Bob.class
CommandPasser$ComA.class
CommandPasser$ComB.class
CommandPasser$ComC.class
CommandPasser$Command.class
CommandPasser$CommandFactory.class
CommandPasser$Fred.class
CommandPasser$Handler.class
CommandPasser$HandlerFactory.class
CommandPasser$RecA.class
CommandPasser$RecB.class
CommandPasser$RecC.class
CommandPasser$Receiver.class
CommandPasser$Sue.class
CommandPasser.class
FlyweightCommand.class
FlyweightFactory.class
How to execute?
%java FlyweightCommand
Files:
FlyweightCommand.java
Use Flyweight pattern to generate a series of buttons. There are
totally three types of buttons: type 0, type 1, and type 2.
Listen to left-mouse clicks. First click will determine the type of
handler, and the second click will determine the type of command.
FlyweightCommand.java will pass (i, handlerType, commandType) to
the pass() function in CommandPasser.java. Here, i is the position
of the button most recently clicked in the button list.
CommandPasser.java
This file is based on the CommandPasser.java used in class.
Totally three types of commands and handlers are defined here:
ComA, ComB, ComC commands and Bob, Fred, Sue handlers.
pass() first computes x and y coordinates from the received i.Then
pass() will also decide which handler to call and designate which
command for the handler to do, based on the information received from
FlyweightCommand.java.
ComA(type 0)-- computes x+y
ComB(type 1)-- computes x^2 + y^2
ComC(type 2)-- computes x^3 + y^3
Bob(type 0)-- present the computed result in Decimal format
Fred(type 1)--present the computed result in Hex format
Sue(type 2)-- present the computed result in Binary format
Huijuan Jiang
Last modified: Sat Nov 9 16:02:27 EST 2002