Objectives Addressed
- understand and apply object-oriented design patterns
- understand the use of UML in the design process
- be able to design and implement small software components and systems
- be able to use computer-aided software engineering (CASE) tools in the design process
Overview
The purpose of this lab is to review an existing design, recognize shortcommings of that design, and apply a design pattern to improve the design.
Problem Statement
Background
Recall the
JavaDrawingProgramDesign, and review the design and implementation provided for this lab. (Note, while it would be nice to continue building off your individual or group's design, it is not practicle in a lab setting since every team likely did the design slightly different. Use the implementation provided as a starting point. Be sure to ask questions if you do not userstand portions of the design).
The current domain model --> class diagram is shown below.
|
| Figure 1. Drawing program user interface class diagram. |
Notice that we have a bit of a problem. We are actually storing two lists of Shapes. How did this situation arise? Recall that the
ShapeManager? object resulted from our desire to separate the "business logic" from the user interface. Thus, although we knew at the time the
ShapeList? object would obviously need to store a list of some type, we did not want to embedd our business logic in a Swing derived class.
So, in some ways, this situation is unavoidable. Is there anything wrong with the design? Should we just accept it and move on?
The risk we might want to minimize is that these two lists become unsynchronized. If you look at the implemenation provided you can see that the Mainframe is pretty much in charge of adding new Shapes, and it does, in fact, add to both lists at the same time. But what about removing Shapes? Since
ShapeList? has a key listener for removal, it takes care of removing from its list right away and then tells the Mainframe to do the same for the
ShapeManager?. Fine for now. But, what happens when we add a key listener to the Mainframe to listen for Ctlr-z (Undo)? Now the lists will become unsychronized. To fix we have to go an modify
ShapeList?, as well as perhaps Mainframe. Not very localized changes.
The Observer Pattern
Enter the Observer Pattern. This pattern is geared for this situation where we have a one-to-many relationship, and wish to keep the many informed of the state of the one. Will it help out in this situation?
Assignment
Main Assignment
- Rework the provided design (in the model provided) to implement the Observer Pattern.
- You may use the Java Observable/Observer if you feel it is appropriate, but you do not have to.
- Create sequence diagrams in the model for UC1 and UC3.
- Generate code and implement your design. You may use the starter project provided below.
Questions
- What are the pros and cons of using Java's Observable / Observer?
- What are some positive results of implementing the observer pattern for this project?
- What are some negative results?
Optional
- The code provided minimally implements drawing of a rectangle only, and has a few hacks along the way. It is not required to address any of these issues right now, but we will be working on some of these details in the future, so you may want to implement some of the missing features (especially drawing the other shapes, and fixing up coordinate handling for Rectangle as well).
- There are a couple of "bugs" in my Canvas class with respect to UC1. What are they and how do we fix them?
Resources
- Sample EA Model: This is a zipped EA model that implements the model shown above. Start with this model.
- Drawingv2.zip: This is a zipped Eclipse project that was created via code generation and implements much of UC1, UC2, and UC3 for a rectangle only. Start with this project.
DrRothe? Deliverables (due at beginning of week 4 lab)
Students should submit:
- A pdf format report with:
- Answers to questions posed above.
- A short discussion about any problems you had with this project.
- New diagrams generated for this lab - also include any changed diagrams that support new diagrams - for example, you should include:
- Sequence diagram with the observer pattern in action (UC1 - Adding a Shape, and UC3 - Erase a Shape)
- Updated class diagram showing observer relationships.
- A .zip file with:
- All source code for this project - no class files please.
- A text file named manifest.txt. Within manifest.txt, list your email addresses (each team member, one per line), and all of the text files
- Submit via electronic submission at online submission as Lab 3.
- Do not include EA file with this submission.
- Your zip file should not have any subdirectories except for Java packages associated with your souce code.
- Log your time spent on this assignment to FAST.
DrTaylor? Deliverables (due 11pm the day prior to week 4 lab)
Students should
submit two files per group:
- An .xml file with:
- Answer to questions posed above.
- A short discussion about any problems you had with this project.
- Links to the UML diagrams (see below).
- A .zip file that has .png or .gif images of:
- Updated UML class diagram (called 2811 login L3a.png) where login is the actual login name for one of the members in your group.
- Updated UML sequence diagram showing the Observer Pattern in action for UC1 (called 2811 login L3b.png).
- Updated UML sequence diagram showing the Observer Pattern in action for UC3 (called 2811 login L3c.png).
- Note: The class diagram should include all methods, attributes and associations required to implement the Observer Pattern.
Also, be sure to submit a log of time spent on this assignment to
FAST.