This design studio will help practice implementing the abstract factory and observer patterns.
Read the slides on Design Patterns, in particular, the abstract factory and observer patterns.
Read the additional reading material posted on the progress page.
Take the Canvas quiz PreQ6.
You will work on the following tasks as a team.
Download the zip file available here
Unzip the files. You should find two folders, AbstractFactory and Observer.
Load these folders as two separate projects in Eclipse.
Work on the Observer example first.
Run the Observer example using Watch2Windows as the main class:
The ColorFrame and ListFrame classes implement the Observer interface. In these classes, the constructor ensures that each observer gets registered with the subject state is the sendNotify method. This is like the update method we discussed in the slides.
The Watch2Windows class implements the Subject interface. It maintains the state that gets selected using Java Swing buttons. You don't need to understand this part of the code now. Just note that the Watch2Windows class implements the registerInterest method, which is used by observers to register themselves with the subject. The Watch2Windows class also contains the main method.
Add a new type of observer window. Make it filter events, so that it changes every second click on the main window. It should not change after every click. The window displays one text field, which lists the time of clicking (HH:MM:SS), using the current selected color. The implementation can be done by by copy-pasting either ColorFrame or ListFrame.
Show one of the instructors or TAs that the observer program works.
Run the AbstractFactory example using Gardener as the main class.
Understand the AbstractFactory example.
The Garden interface is the supertype in the Abstract Factory hierarchy. note that every garden must contain a plant that grows in the shade, one that grows in the center, and one that grows in the border.
The AnnualGarden, PerennialGarden, and VeggieGarden classes are concrete factories that implement the Garden interface. The AnnualGarden factory creates a plant that is annual and also grows in the shade, another plant that is annual and also looks nice in the center of the garden, and a third plant that is annual and also looks nice in the border of the garden. Similarly the other factories also produce plants for the shade, center, and border, but have the characteristic that the plant is perennial or is a vegetable.
The Gardener class contains the main method. It sets up the panel of radio buttons for selecting the factory on the left (e.g., Vegetable, Annual, and Perennial). The panel for selecting the position of the plant using buttons is in the bottom right. The panel showing the actual garden layout is in the top left.
The Plant class represents a product. For simplicity, there are no subtypes of Plant. Instead the actual plant name is provided as a String argument to the Plant constructor.
The classes Command and CheckCommand are used to implement the Command design pattern, which you don't really need to know at this point.
Add a new type of garden by implementing a new factory that implements Garden. Add a new type of area (e.g., Bright), which means you need to change the interface Garden and all the existing implementations of Garden.
Choose an appropriate set of plants to go with the gardens and areas. Use your imagination for naming the plans. This isn’t a botany test. Modify the GUI to include the new type of garden and type of area.
Make sure that the Gardener class shows the new radio button for the new type of garden as well as a new button for the new area.
Package the folders for both Abstract Factory and Observer in a zip file.
One person in your team needs to submit the zip file in the Canvas dropbox for DS6.