Design Patterns - Assignment Sample 6 With Answers
Design Patterns - Assignment Sample 6 With Answers
Design Patterns - Assignment Sample 6 With Answers
Patterns
Template Pattern:
State:
Strategy:
Command:
2. Build generic Interaction Diagram for each pattern in lesson (as presented in
class)
Template Pattern:
State:
Strategy:
Command:
3. Find an example (not used in the class or class books) of the use of one of the
patterns from this lesson and write a 2-3 page description of the use of the
pattern in the example.
• Describe the pattern, describe the problem being solved, describe how
using the pattern solves the problem and describe the benefits of
using the pattern.
• Illustrate with Object Models.
• Use your own words to describe the example not just the words from
the reference.
• Use appropriate references in IEEE style. Including providing a
reference to where you found the example.
Select one from this list of patterns.
• Template
• State
• Strategy
• Command
Strategy Pattern:
pattern. This design pattern helps us build a family of different but related
the best software design pattern solution for situation when we need to
circumstances.
approach can be used as a good alternative to sub classing. The client selects
the actual implementation of the algorithm from the group of algorithms at
Strategy Pattern is sometimes known as Policy Pattern. The client pass the
argument to the method and the context object does not have any variable to
store it as in case of State Pattern 1. Strategy Pattern captures the abstraction
1 P. Kumar, "Strategy Design Pattern in Java - Example Tutorial - JournalDev", JournalDev, 2018.
[Online]. Available: https://www.journaldev.com/1754/strategy-design-pattern-in-java-example-
tutorial. [Accessed: 05- Dec- 2018].
2 "Design Patterns and Refactoring", Sourcemaking.com, 2018. [Online]. Available:
select appropriate payment options and ease the whole process maintaining
3P. Kumar, "Strategy Design Pattern in Java – Example Tutorial", journaldev.com, 2018. [Online].
Available: https://cdn.journaldev.com/wp-content/uploads/2013/07/Strategy-Pattern.png.
[Accessed: 05- Dec- 2018].
4. Create a list of all 23 patterns and find an example in Java (standard Java
implementation) of a use of each pattern and explain how it works.
6. Observer: The observer pattern is used when change in one object needs to
reflect in other objects and maintain loose coupling.
Used in java: javax.servlet.http.HttpSessionAttributeListener
10. Flyweight: Flyweight Pattern help reduce the number of objects and decrease
memory footprint and increase performance. New objects are created only
when needed.
Used in java: java.lang.Integer#valueOf(int)
11. Builder: The builder pattern is an object creation software design pattern.
Unlike the abstract factory pattern and the factory method pattern whose
intention is to enable polymorphism, the intention of the builder pattern is to
find a solution to the telescoping constructor anti-pattern.
Used in jave: java.nio.ByteBuffer#put()
12. Factory method: Define an interface for creating an object, but let subclasses
decide which class to instantiate. The Factory method lets a class defer
instantiation it uses to subclasses.
Used in java: java.nio.charset.Charset#forName()
13. Abstract factory method: Abstract factory returns factory of method which in
turn creates another abstract class or interface.
Used in Java: javax.xml.xpath.XPathFactory#newInstance()
Lesson 7 Preparation
6. Read Chapter 21-22-23-24 Java Design Patterns (will be on quiz)
7. Read Sections in Design Patterns book (will be on quiz)
• Interpreter p. 243
• Decorator p. 175
• Iterator p. 257
• Visitor p. 331