Anda di halaman 1dari 2

TCP2201

Object Oriented Analysis and Design


Lab 11 Design Patterns


Lab outcomes

By the end of todays lab, you should be able to
differentiate design patterns and apply them to particular scenarios

Design patterns

1. Define the reasons of when to implement the following design patterns
DP
Reasons to implement
Singleton

Prototype

Builder

Adapter

Bridge

Composite

Decorator

Faade

Iterator

Observer

Strategy


2. Complete the following table by filling in the possible design pattern that can be applied
in a scenario based on the following phrases

System design key phrase
Possible design pattern
Must support future protocols/objects with
the same interface
Allows the abstraction of runtime from the
frontend interface
Supports aggregate structures

Allows for object hierarchies of variable
depth and width
Must comply with existing interface

Reuses legacy components
Allow different algorithms to be

interchanged during runtime
Decouples policy and mechanisms
Multiple events triggered by a single source
creates objects that monitor or observer
conditions

TCP2201-T11/2014.15/WKS

3. Consider the earlier tutorial about writing the Java code for a game of Tic-Tac-Toe. We
are now interested in translating this bridge game into a different programming langauge
by implementing a new interface but retaining the gameplay logic and as much other code
as possible. Which design pattern would you use? Draw a UML class diagram relating the
objects in the new and old game together.

4. Consider the following design goals. Indicate the candidate pattern(s) you would
consider to satisfy each goal:
Given a legacy banking application, encapsulate the existing business logic
component.
Given a chess program, enable future developers to substitute the planning
algorithm that decides on the next move with a better one.
Given a chess program, enable a monitoring component to switch planning
algorithms at runtime, based on the opposing players style and response time

5. Consider an application that must select dynamically an encryption algorithm based on
security requirements and computing time constraints. Which design pattern would you
select? Draw a UML class diagram depicting the classes in the pattern and justify your
choice

6. Compare and contrast between the observer design pattern and the listeners
implemented in Java libraries (i.e. MouseListener, ActionListener etc.)

7. You are tasked to writing the software logic for controlling a electronic hand dryer. The
dryer has a IR sensor which can determine whenever someone's hands are placed under it.
This triggers the dryer to start blowing hot air for a fixed amount of time. The dryer can also
be triggered via a push button on the front of the unit. Once the unit starts blowing, we do
not want additional button pushes or triggers of the light sensor to extend the air blowing
cycle.

Select the most appropriate design pattern to use to address the problem and show how it
is applied. Show an appropriate class diagram(s) and enough code fragments to illustrate
your use of the pattern to solve the problem.

8. The faade and observer patterns were listed to reduce coupling between objects.
Discuss how the use of these patterns reduce coupling.


NOTE : additional reference for design patterns
http://www.tutorialspoint.com/design_pattern/index.htm
https://thenewcircle.com/static/bookshelf/java_fundamentals_tutorial/index.html
http://www.oodesign.com/

TCP2201-T11/2014.15/WKS

Anda mungkin juga menyukai