The Artima Developer Community
Sponsored Link

Joystick Bean (JoyBean?)

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Joystick Bean (JoyBean?)

Posted by Mark Johnson on 22 Sep 1998, 10:27 AM

> Instead, it uses a factory method to get an array of all the joysticks currently attached to the system, so I don't need to do anything special if there aren't any

Nice use of the factory pattern to abstract construction. I like it.
What I'd do in this case, Andrew, is create a JoyBean class
that accesses that JoystickFactory class and asks it for its
list of JoyStick objects. If there aren't any, the JoyBean
disables itself; if there is only one JoyStick, it uses it, and if there
are more than one, it uses the "default" JoyStick (something
statically defined in the JoyStickFactory class itself), but provides
a Customizer that allows you to override which one is being used.
Your GUI could then contain a menu item (Select Joystick...)
that simply activates the JoyBean's Customizer, allowing the user
to select the JoyStick to which the JoyBean defers all its actions.
JoyBean is an example of the "Facade" pattern that
presents the JoyStick API to the application, but defers all actual
operations to a particular object (in this case, one object in a
pool of pre-existent resources.)

By the way, notice that this is an example of "beanifying"
by simply defining reasonable default behavior, as discussed
in the "debate".

--Mark Johnson
JavaWorld






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us