For this lab, you will introduce the Decorator Pattern into the bees and garden system you wrote for the previous lab. Each team member must introduce at least one decorator, but a team member can implement additional decorators if they like. Be sure to fix issues identified in the previous lab as well. The intent is that this would be done using the same groups as the previous lab; if this would be difficult for you, talk to your instructor as soon as possible.
Members will pick one of the following features to implement using the Decorator Pattern. In each case, there must be multiple, distinct decorators, and decorators must be able to decorate both the base object and decorated objects.
Add additional behaviors and images to flowers. For example, a flower might trap a bee for a given number of moves, you might add stems and leaves, or you might add a feature that repels bees for a time. The decorators must be applicable to all types of flowers.
Add additional behaviors and images to bees. For example, you might add a top hat to the bee (maybe to make the program more interesting to children), have the bee get pushed by a gust of wind for a time, or introduce polinator bees that make flowers “go to seed”. The decorators must be applicable to all types of bees.
Use decorators to redefine how pattern bees move. One decorator might make the bee move horizontally, and another move vertically, so a bee with both moves at a diagonal (with appropriate logic for reversing direction at the edges of the garden). Additional decorators would make the bee move faster. For this to work, you may need to remove any implementation of the Strategy Pattern you previously introduced. This decorator would apply to just the pattern movement bee.
Add a decoration to the garden to add a set number of trees or a set number of weeds. Note it would be possible to use multiple decorators to include yet more trees and/or weeds. Each of these decorations should introduce a preset number of objects (say, five trees) at random locations.
Introduce a bee keeper and use decorations to change their clothing. They might take damage from bees if they are not wearing protective netting.
If you have alternative ideas, feel free to discuss them with your instructor. Alternatives must be approved. Use Teams or email to present the alternative so you get a written approval.
All decorators must have the following properties:
They must modify the image in a visible way so users can tell which bees or flowers should have changed behavior.
There must be at least two or three types of decorators for each type of object that gets decorated.
As stated above, it must be possible to “stack” decorators; that is, it must be meaninful to decorate a previously-decorated object.
There must be a way for the user to control how decorators are applied. One model is to allow the user to enable or disable specific decorators and apply the decorators randomly: say a button to add a specific decorator to a random subset of the objects. Another is the user could have an interface allowing them to create a specific number of objects with collections of decorators.
The intent is that all decorators would be determined at object creation time. It is possible to use the decorator pattern with objects that change state, but this introduces significant complexities. In particular, you will need a “dummy” object that holds the primary reference to the decorated object. If you are interested in doing the extra work, discuss it with your instructor.
Each student in the group must implement at least one, distinct decorator.
When applying the Decorator Pattern, you must use the word Decorator
in
the class names of all decorators; this allows instructors to identify
where you have applied the pattern. In addition, follow the notes and make
sure the class being decorated is an interface
class. This introduces two
issues:
Many solutions derive the Bee
and Flower
classes from an abstract
garden object class. You will want to introduce (say) a BeeInterface
class that is not derived from garden object since you cannot derive an
interface from a non-interface class. Then your abstract Bee
class
would extend the garden object but implement the bee interface.
If you have multiple types of bee objects that can be decorated, making them implement a bee interface leads to duplicated code between the bee objects. Likewise, the same happens if you have multiple types of flower objects derived from a flower interface class. Fix this by creating an abstract bee or flower that implements the flower or bee interface, and putting all common code into the abstract class.
Ensure that your user experience is still appropriate. This includes making it easy for your instructor to verify the new features in half a minute or so.
Checked that issues identified in the previous lab have been fixed. Talk to your instructor if an issue is too difficult to fix without an extensive rewrite,
As for the previous lab, meet your instructor’s coding standard. At a minimum, your classes must include documentation about their responsibilities.
Push your changes to your Git repository, continuing to work on the main branch.
When you are finished, create a PDF
capturing what you accomplished. Your instructor may have specific requirements to meet, but if the instructor does not specify then your PDF must contain the following:
Main
class or JavaFX classes, and do not reverse-engineer your solution to create this diagram.See Canvas for any additional submission instructions.