COMP 310
|
Composition-based Ballworld Demo
with Multiple Switchers
|
|
Note: it is
an Honor Code violation to attempt to decompile any supplied code
There is a web page that explains how this
demo makes multiple switcher balls that will only be made available by the
instructor after a specified date.
This composition-based Ballworld demonstrates the ability of composition-based
systems to add dynamically modifiable behaviors to a system, plus adds the
ability to create multiple, independent switcher strategies. It is
an extension of the regular
composition-based Ballworld demo.
- Type the name of a strategy into the text field on the left. See the
list below for the available strategies. Clicking the "Add
to Lists" button will then add it to both the drop lists.
- "Make Selected Ball" will make
a ball with the strategy selected on the top drop list.
- "Combine!" will dynamically
create a strategy that is the combination of the strategies selected on top
and bottom lists. The new strategy is placed back into both drop lists and can
be used again for combining. For instance, add then combine "Curve"
and "Breathing" to make a ball that curves and breathes.
- "Add Switcher" will
add a factory for a switcher ball to the drop list. The name of
the new switcher strategy will be "Switch N" where N is an
integer starting at 1. Initially, unless switched to a new strategy,
the balls made with the new switcher strategy factory will behave as the
selected strategy on the top drop list when the "Add Switcher" button was
clicked. This process will also create a matching
"Switch N" button on the GUI that will switch the behavior of all
switcher strategies made with the "Switch N" strategy factory.
- Clicking one of the "Switch N"
buttons will cause all balls made with switcher strategies associated with
that button to switch behaviors to whatever is the selected
strategy on the top drop list. Switcher balls made later using the same
switcher strategy factory will have the same
behavior as whatever the previously made Switchers from that factory have.
If you hold the mouse over any button, a tooltip will pop up that will tell
you what that button does.
The following different types of strategies are available for use,
plus any switcher strategies created:
- Straight
- Curve
- Color
- Breathing
- Wander
- Drunken
- Change1
- Change2
Try combining switcher strategies and see
what happens!
Important Design Notes
This code has the following design features:
- Does NOT CONTAIN AN ARRAY of switcher strategies anywhere.
- No references to the created switcher strategies are maintained
within the model.
- No structure or process exists anywhere in the system that manages
the created switcher strategies (other than objects that hold them
individually).
- NO BALL REFERENCES are maintained, other than internally by the
dispatcher.
- There are NO ITERATIONS OVER THE BALLS for any purpose (other than
perhaps internally to the dispatcher).
- There is NO PER-BALL MANAGEMENT anywhere.
- Does not couple the view to the model in any manner.
- There are NO COMMON INTERFACES OR CLASSES to both the model and the
view.
- The view has no notion of strategies, factories, switchers, etc.
- The model has no notions about buttons, drop lists, action
listeners, etc.
- There is NO named switcher strategy class anywhere in the system.
- There is NO named composite strategy class anywhere in the system.
- The "Switch N" buttons are
created and connected at run-time when the "Add
Switcher" button is clicked.
- Essentially a "mini-MVC" is dynamically created for every switcher.
- Execution loops, e.g. a switcher is asked to switch to itself, are
detected and behavior is reduced to a no-op (straight ball) in those
situations. An error message is printed out to the Java Console.
[ Back to the Ballworld Demos ]
Trouble Running the Demos?
© 2017 by Stephen Wong