More on design patterns and Final Review

advertisement
Session 30
Final Review
Final Details
•
•
•
•
•
•
Wednesday, December 14 at 8 AM
Wright 5 (same classroom)
Final will be comprehensive
Open book
Open notes
Test is about half coding and half short
essay questions (similar to Tests 1 and 2)
Final Material
• Chapter 15 – Design Patterns and MVC
• Chapter 13 -- AWT mostly covered previously
– Look for design patterns in the AWT framework
• Chapter 14 – Some file questions. Look for
design patterns in the way Java files are
organized
• Test 1 Material
• Test 2 Material
General Study Hints
1. Go through each chapter and making a
list of the vocabulary terms that we have
discussed. Could you explain what each
means and how they relate to each other?
2. Review the slides I used during class
and consider the points I have
emphasized either directly on the slides or
in addition to the slides.
Study Hints
3. Review the programs we have worked with (Pinball
Game Versions 1-3, Set example using composition,
Projectile, Pinball Pallet exercise solution, my Tic Tac
Toe solution for HW5, etc). I will provide you with any
code I expect you to use/modify, but you don’t want to
waste test time reviewing how the code actually works.
4. Read through the questions at the end of the
chapters. Play the "second guess” the instructor game.
That is, think about what you reviewed in the previous
steps and think about how well each question would fit
into these topics. Some of my questions will come from
these questions. Others will be modifications to these
questions based more on what I have chosen to
emphasize.
Adapter Design Pattern
• Problem: How do you use an object that
provides appropriate behavior but uses a
different interface than is required in some
situation?
• Solution: Define an adapter class that acts as
an intermediary. The adapter merely translates
commands from one form into another
• Example: InputStreamRead and OutputStream
Writer translate from input/output stream
interface into the required reader/writer interface
Composite Design Pattern
• Problem: How do you permit the creation of
complex objects using only simple parts?
• Solution: Allow simple components to be nested
arbitrarily
• Example:
– Design layout through the interaction of Components
and Containers.
– Each item in a layout is a Component.
– Composition occurs because Containers are also
Components
Flyweight Design Pattern
• Problem: How can one reduce the storage costs
associated with a large number of objects that
have a similar state?
• Solution: Share state in common with similar
objects, thereby reducing the storage required
by any single object.
• Example: the way Java maintains type
information about classes, e.g., type name,
description of the interface, etc.
– e.g., one Class object for all Strings
Abstract Factory Design Pattern
• Problem: How to provide a mechanism for creating
instances of families of related objects without specifying
their concrete representations.
• Solution: Provide a method that returns a new value that
is characterized only by an interface or parent class, not
by the actual type produced.
• Example: Collection classes (e.g., Vector) define a
method named elements() that is described as returning
a value of type Enumeration.
– Enumeration is only an interface, not a class
– the client is only interested in the behavior common to all values
that satisfy the Enumeration interface
Factory Design Pattern
• Problem: You have a method that returns
a newly created object, but you want
subclasses to have the ability to return
different types of objects.
• Solution: Allow the subclass to override
the creation method and return a different
type of object.
• Example: the clone() method returns a
copy of an object
Iterator Design Pattern
• Problem: How to provide a way to access
elements of an aggregate object
sequentially without exposing the
underlying representation.
• Solution: Provide a mediator object for the
sole purpose of sequential access.
• Example: The Enumeration interface
includes methods for hasMoreElements()
and nextElement().
Other Design Pattern
• Decorator
• Proxy
• Bridge
Download